MongoDB  2.7.0
Public Member Functions | List of all members
mongo::BSONFieldValue< T > Class Template Reference

A BSONField holds the name and the type intended for a given BSON element. More...

#include <bson_field.h>

Public Member Functions

 BSONFieldValue (const std::string &name, const T &t)
 
const T & value () const
 
const std::string & name () const
 

Detailed Description

template<typename T>
class mongo::BSONFieldValue< T >

A BSONField holds the name and the type intended for a given BSON element.

The class helps documenting and enforcing that field's type.

Example usages:

In a header file:
// Determines the types for the fields used in a collection.
static const string MyColl;
struct MyCollFields {
    static BSONField<string> name;
    static BSONField<bool> draining;
    static BSONField<int> count;
};

In a cpp file:
const string MyColl = "my_collection_name";

// determines the names used for the fields
BSONField<string> MyCollFields::name("_id");
BSONField<bool> MyCollFields::draining("draining");
BSONField<int> MyCollFields::count("count");

In an insert:
conn->insert(myColl,
             BSON(MyCollFields::name("id_for_this_doc") <<
                  MyCollFields::draining(true) <<
                  MyCollFields::count(0)));

In a query:
conn->findOne(myColl, BSON(MyCollFields::count.gt(10))) ;

In a command:
conn->ensureIndex(mycoll, BSON(MyCollFields::draining() << 1), true);

The documentation for this class was generated from the following file: