Bson.opIndex

Allows accessing fields of a BSON object using [].

Returns a null value if the specified field does not exist.

  1. inout(Bson) opIndex(string idx)
    struct Bson
    @safe inout
    inout(Bson)
    opIndex
    (
    string idx
    )
  2. inout(Bson) opIndex(size_t idx)

Examples

Bson value = Bson.emptyObject;
value["a"] = 1;
value["b"] = true;
value["c"] = "foo";
assert(value["a"] == Bson(1));
assert(value["b"] == Bson(true));
assert(value["c"] == Bson("foo"));
auto srcUuid = UUID("00010203-0405-0607-0809-0a0b0c0d0e0f");

Bson b = srcUuid;
auto u = b.get!UUID();

assert(b.type == Bson.Type.binData);
assert(b.get!BsonBinData().type == BsonBinData.Type.uuid);
assert(u == srcUuid);

Meta