Ionut Grad
Ionut Grad

Reputation: 11

Is there a way to add local bson documents to mongodb using mongocxx driver?

I have a few bson files which i need to insert into the mongodb using c++ code. Is there any way to insert a bson document into mongodb using mongocxx driver? I am using ubuntu, and all I could get was to manually create the document inside the code.

Upvotes: 1

Views: 148

Answers (1)

gouy_e
gouy_e

Reputation: 188

MongoDB doesn't have an API to manipulate BSON files, so you'll need to use an external tool:

  • Use mongorestore to import your BSON files, you can launch it from your C++ code using exec or alike functions.
  • Or you could use bsondump to create a JSON file from your BSON file and then insert it using the C++ driver, but as mentioned on the doc page: bsondump is a diagnostic tool for inspecting BSON files, not a tool for data ingestion or other application use.

Upvotes: 1

Related Questions