Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Import .bson file format on mongodb

Tags:

mongodb

People also ask

How do I open a .BSON file?

If you cannot open your BSON file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a BSON file directly in the browser: Just drag the file onto this browser window and drop it.

How do I import a MongoDB file?

You can use the mongoimport command to import CSV files into a collection using the headerline option. Headerline option notifies the mongoimport command of the first line; to be not imported as a document since it contains field names instead of data.

How do I import a JSON and BSON file into MongoDB?

Open the Import Wizard. Then, select BSON – mongodump folder or BSON – mongodump archive as the import format. For both types, you will need to configure a 'mongorestore' executable under Preferences > MongoDB tools. Click on the folder icon and choose the root mongodump folder to be imported.


It's very simple to import a .bson file:

mongorestore -d db_name -c collection_name /path/file.bson

Incase only for a single collection.Try this:

mongorestore --drop -d db_name -c collection_name /path/file.bson

For restoring the complete folder exported by mongodump:

mongorestore -d db_name /path/

Note: If you have enabled authentication use the below syntax:

mongorestore -u username --authenticationDatabase admin -d db_name -c collection_name /path/file.bson

mongorestore is the tool to use to import bson files that were dumped by mongodump.

From the docs:

mongorestore takes the output from mongodump and restores it.

Example:

# On the server run dump, it will create 2 files per collection
# in ./dump directory:
# ./dump/my-collection.bson
# ./dump/my-collection.metadata.json
mongodump -h 127.0.0.1 -d my-db -c my-collection

# Locally, copy this structure and run restore.
# All collections from ./dump directory are picked up.
scp user@server:~/dump/**/* ./
mongorestore -h 127.0.0.1 -d my-db

bsondump collection.bson > collection.json

and then

mongoimport -d <dbname> -c <collection> < collection.json

Just for reference if anyone is still struggling with mongorestore.

You have to run monogorestore in terminal/command prompt and not in mongo console.

$ mongorestore -d db_name /path_to_mongo_dump/

for more details you can visit official documentations

https://docs.mongodb.com/manual/reference/program/mongorestore/