Reputation: 78244
I was given a data dump of bson files. In the mongo db, the database and the collections exists. These are updates to each of the collections in the database. So, in the given directory, there are about 30 bson files for each collection.
From the command line, I am using ubuntu, how do I append and load? Mongo is on my localhost with no username or password.
Thanks
Upvotes: 8
Views: 28350
Reputation: 172
1) Go to the directory where the "dump" folder is located in CMD.
2) Run the mongorestore command.
Upvotes: 0
Reputation: 8847
Took me a while to get around this excuse for an error. In the end I went to the directory outside of my dump
folder, and did the following...
For a full DB restore:
mongorestore --drop dump/mydb
Note that the mongodump
operation will create individual folders for each database within the dump
folder it creates, so you need to specify the full relative path, as above.
For a single collection:
mongorestore --drop -d mydb -c mycollection dump/mydb/mycollection.bson
Upvotes: 5
Reputation: 639
import Bson
import Json
http://docs.mongodb.org/v2.2/reference/mongoimport/
Upvotes: 1
Reputation: 5172
The usual syntax is:
mongorestore -d dbname -c collectionname dir/file.bson
Upvotes: 3
Reputation: 43884
Since Mongo restore does not update the current records this would not be a good choice.
Mongorestore only appends new records as stated:
mongorestore just does inserts with the data to restore; if existing data (like with the same _id) is there it will not be replaced.
You may wish to build a BSON parser in your language of choice and make a more complex tool than mongorestore, since mongorestore is only designed to "restore" (as the name kinda suggests) a database/collection you will need to write something a little more complicated to do what you want and that depends heavily on your server-side language.
This is actually better done with mongoexport and mongoimport:
http://www.mongodb.org/display/DOCS/Import+Export+Tools#ImportExportTools-mongoimport
With mongoexport you could export a JSON file and give the command line for it do upserts. So I would personally go back to the person who gave this file and tell them that you actually want a mongo export file instead.
Upvotes: 0
Reputation: 3100
are you looking for mongorestore? http://www.mongodb.org/display/DOCS/Import+Export+Tools#ImportExportTools-mongorestore
Upvotes: 2