发布于 2015-09-14 15:11:02 | 165 次阅读 | 评论: 0 | 来源: 网络整理

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 included explicitly.

    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 }
    
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务