1

The underlying goal here is read json with arrays sub documents and whatever in string format {key:"value", boolkey, true, {subkey: value}, array: [x,y,z] } and not caring to undertake append_int, append_bool and all that jazz.

any way of using the convenient C++ BSONObj, mongo::fromjson BSONObjBuilder to finally output a C bson_t.

ie. along the lines of either

 mongo::BSONObj& query = mongo::fromjson ( szJSON );
 bson_t bson = query.c_obj();

or

 BSONObj Builder builder;
 ... (build, build, build)

 BSONObj obj = builder.obj();

 bson_t bson = obj.c_obj();

given that c++ is built on the c driver one would think that the bson_t is lying within somewhere

Gabe Rainbow
  • 3,658
  • 4
  • 32
  • 42
  • `bson_t` is C API, while `BSONObj` is C++ API. What's the reason to mix them? – John_West Aug 21 '15 at 11:51
  • c++ driver is complex, not very stable. c driver is the foundation for many drivers so assume its stable. c bson library on the other hand is awkward to use. – Gabe Rainbow Aug 27 '15 at 21:29

1 Answers1

1

You can use

bson_t* b = bson_new_from_data(obj.objdata, obj.objsize)

but you will always create objects twice.

Totonga
  • 4,236
  • 2
  • 25
  • 31