What is the syntax for storing large binary array in a BSON in C++?

385 views
Skip to first unread message

Alex

unread,
Oct 20, 2011, 2:37:28 PM10/20/11
to mongodb-user
Greetings!

I realize this is somewhere in the docs, but I just can't find it. How
do I store binary array in a BSON in C++?
Also, do I have to take certain steps to enable GridFS, or is it
enabled by default?

Thanks!

Spencer T Brody

unread,
Oct 20, 2011, 7:04:59 PM10/20/11
to mongod...@googlegroups.com
To create a BSONObj in C++ that stores binary data, you can do something like:

BSONObjBuilder builder;
b.appendBinData ("fieldname", datasize, BinDataGeneral, data);
BSONObj obj = builder.obj();



GridFS is a client-side specification - nothing needs to be enabled on the server, you can just use the gridfs client in the C++ driver to put and fetch gridFS data from your mongo cluster.  The GridFS C++ client documentation is here: http://api.mongodb.org/cplusplus/current/classmongo_1_1_grid_f_s.html.

Hope that clears things up!
-Spencer
Reply all
Reply to author
Forward
0 new messages