Serializes the given value to BSON.
Represents a BSON value.
Represents a BSON binary data value (Bson.Type.binData).
Represents a BSON date value (Bson.Type.date).
Represents a BSON object id (Bson.Type.binData).
Represents a BSON regular expression value (Bson.Type.regex).
Serializes to an in-memory BSON representation.
Represents a BSON timestamp value (Bson.Type.timestamp).
private
void manipulateBson(Bson b) { import std.stdio; // retrieving the values is done using get() assert(b["name"].get!string == "Example"); assert(b["id"].get!int == 1); // semantic conversions can be done using to() assert(b["id"].to!string == "1"); // prints: // name: "Example" // id: 1 foreach (string key, value; b) writefln("%s: %s", key, value); // print out with JSON syntax: {"name": "Example", "id": 1} writefln("BSON: %s", b.toString()); // DEPRECATED: object members can be accessed using member syntax, just like in JavaScript //j = Bson.emptyObject; //j.name = "Example"; //j.id = 1; }
Constructing Bson objects
// construct a BSON object {"field1": "foo", "field2": 42, "field3": true} // using the constructor Bson b1 = Bson(["field1": Bson("foo"), "field2": Bson(42), "field3": Bson(true)]); // using piecewise construction Bson b2 = Bson.emptyObject; b2["field1"] = "foo"; b2["field2"] = 42; b2["field3"] = true; // using serialization struct S { string field1; int field2; bool field3; } Bson b3 = S("foo", 42, true).serializeToBson();
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
© 2012-2015 Sönke Ludwig
BSON serialization and value handling.