C++ BSON 帮助函数

本文概述了在C++中使用BSON宏函数与MongoDB交互的方法,包括GENOID、LT、GT等操作,用于创建如_id、日期、比较条件等BSON对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文介绍BSON宏函数在mongodb中的使用。

This is a non-exhaustive list of helper functions for use in the C++stream syntax. An exhaustive list is here: bsonmisc.h

Typical example of stream syntax:

BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
  • GENOID

    The server will add an _id automatically if it is not includedexplicitly.

    BSONObj p = BSON( GENOID << "name" << "Joe" << "age" << 33 );
    // result is: { _id : ..., name : "Joe", age : 33 }
    
  • LT, GT, LTE, GTE, NE

    less than, greater than, etc.

    BSONObj p = BSON( "age" << GT << 21 );
    // result is:  { age : { $gt : 21 } }
    
  • DATENOW

    Translates to current date

    BSONObj p = BSON( "created" << DATENOW );
    // result is: { created : "2009-10-09 11:41:42" }
    
  • MINKEY, MAXKEY

    BSONObj p = BSON( "a" << MINKEY);
    // result is: { "a" : { "$minKey" : 1 } }
    

    OR

    OR(BSON("x" << GT << 7), BSON("y" << LT << 6))
    // result is: {$or: [{x: {$gt: 7}}, {y: {$lt: 6}}]}
    
  • BSONNULL

    Translates to null value (will appear in MongoDB 2.1)

    BSONObj p = BSON( "name" << "Methuselah" << "age" << BSONNULL );
    // result is: { name : "Methuselah", age : null }
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值