Skip to content

Tutorial

Tyler Brock edited this page Apr 17, 2014 · 41 revisions

BSON

Working with BSON

BSON Macros

BSON() BSONArray()

BSON Builders

BSONObjBuilder BSONArrayBuilder

BSON Element

Using the driver

#include "mongo/bson/bson.h"
#include "mongo/client/dbclient.h"

Making a Connection

using namespace mongo;
DBClientConnection conn;
conn.connect("localhost");

Using the Connection Pool

ScopedDbConnection conn("localhost");

// The scoped connection can be used like a pointer to a connection
conn->query();
// etc

// When finished with the connection you must call done
conn.done();

Inserting a Document

conn.insert(
    "test.test",
    BSON(
        "name" << "Tyler" <<
        "age" << 29 <<
        "awesome" << true
    )
);

Querying for a document

Updating a document

Removing a document

Clone this wiki locally