myWallJSON
myWallJSON

Reputation: 9522

C++ BSON Library how to load bson from c_str()?

Say we have a string with binary bson data inside. How to load it into bson object?

Upvotes: 0

Views: 1989

Answers (3)

user1208494
user1208494

Reputation: 1

For raw json string use mongo::fromjson

mongo::BSONObj object = mongo::fromjson("{"Login":"test","Password":"12345","Role":["admin","manager"]}");

Upvotes: 0

gage
gage

Reputation: 109

try BSONObj p(you_data_pointer);

Upvotes: 1

ckhan
ckhan

Reputation: 4791

I think there's an example to do just that on that same page:

BSONObjBuilder b;
b << "name" << "Joe" << "age" << 33;
BSONObj p = b.obj();

That is, BSONObjBuilder has a stream operator for const char *.

From the docs:

BSONObjBuilderValueStream & operator<< (const char *name)
Stream oriented way to add field names and values. 

Upvotes: 1

Related Questions