MongoDB C++ Driver  legacy-1.1.2
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>

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))) ;

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