Insert from JSON file using C Driver.

211 views
Skip to first unread message

Antoine

unread,
Dec 26, 2011, 12:11:08 PM12/26/11
to mongodb-user
Hi List,

I'm new to MongoDB and still evaluating it. I am writing an
application that uses JSON to store data into text files. I would like
to have this application working with mongoDB. Is they a way to import
the JSON String into a MongoDB collection using the C driver ?. As far
I have seen, I could only insert BSON objects, but no way to fill a
BSON object from JSON String.

Any tricks for that ?

Thanks for help!

/Antoine

Nat

unread,
Dec 26, 2011, 9:40:36 PM12/26/11
to mongod...@googlegroups.com
MongoDB C driver doesn't parse JSON. You have to use JSON parser to read JSON string and parse them into BSON representation manually.

Gergely Nagy

unread,
Dec 27, 2011, 5:33:46 AM12/27/11
to mongod...@googlegroups.com
> I'm new to MongoDB and still evaluating it. I am writing an
> application that uses JSON to store data into text files. I would like
> to have this application working with mongoDB. Is they a way to import
> the JSON String into a MongoDB collection using the C driver ?. As far
> I have seen, I could only insert BSON objects, but no way to fill a
> BSON object from JSON String.

It is certainly possible with the official C driver too, as Nat wrote,
but this question was asked before, a couple of months ago. At that
point, I threw together a short tutorial using my libmongo-client C
library and json-c.

The tutorial is available at
http://algernon.github.com/libmongo-client/tut_json2bson.html (source
at https://github.com/algernon/libmongo-client/blob/master/docs/tutorial/examples/tut_json2bson.c)

Hope that helps.

--
|8]

Reply all
Reply to author
Forward
0 new messages