user2981029
user2981029

Reputation: 584

Import a data base file.json into robo3T (robomongo)

I have a file named services.json containing a data base that I exported from a windows mongodb, and I want to import that file into robomongo (connected to mongodb installed by npm) on Ubuntu.

I'm a beginner and I don't know how to proceed, which terminal use (robomongo or Ubuntu)?

Upvotes: 24

Views: 73246

Answers (9)

Harsh Patel
Harsh Patel

Reputation: 6830

There are two ways to import the database into MongoDB. one is with robomongo/Robo 3T and one is with a shell command. I always choose the second method due to fewer and easy steps.

FIRST METHOD

Install MongoDB on your machine. Also, check it was installed properly or not by using mongod command on your terminal. So, for importing a new DB on your MongoDB write this command on your terminal

mongostore -host <HostIp | 127.0.0.1> -port <mongoPort | 27017> -db <DBname> <Directory-path>

So, for example you’re running MongoDB on local machine with default port i.e 27017 and your DB files are store at /usr/library/userDatabase then write this command and check DB is imported in your MongoDB

mongostore -host 127.0.0.1 -port 27017 -db userDatabase /usr/library/userDatabase

For more details check this article. Import MongoDB using shell and robomongo/Robo 3T

Upvotes: 0

panzerstadt
panzerstadt

Reputation: 53

I don't have enough points to comment on Varun's answer, but if you use export jsonArray and then import using Robo3T (Robomongo), make sure to remove the commas in between the objects, as well as remove the square brackets.

It's not really a JSON format that ROBO 3T accepts, but rather bunch of JSON objects separated by newlines.

(if you use export Standard, then it's already formatted for document insert)

Upvotes: 5

mantzouric
mantzouric

Reputation: 1

Insert Document will insert all the JSON file data under a single document. Apparently the tool does not support JSON import.

Upvotes: 0

K78
K78

Reputation: 29

Tested :

mongoimport --jsonArray -d <DataBase Name> -c <Collection Name> --file /path/to/my/fileThatIwantToImport.json

It works very well!

Upvotes: 2

user2981029
user2981029

Reputation: 584

Ok, I found the answer. In shell Mac OS X or Unix type:

$ mongoimport -d your Database Name -c your Collection Name --file /path/to/my/fileThatIwantToImport.json

Upvotes: 10

Mohd Belal
Mohd Belal

Reputation: 1199

RoboMongo is just the UI for your mongod which is the primary daemon process for the MongoDB system.

The only option to import from RoboMongo is

Right Click on Collection -> Insert Document

Apart from this you can import using the mongoimport command from terminal.

  1. Open terminal and type mongo
  2. Now in mongo interactive shell
  3. Use the following command to import the json file as collection

mongoimport -d database_name -c collection_name --file < path to the json file

Upvotes: 3

Varun Sukheja
Varun Sukheja

Reputation: 6548

to import data for a collection in Robomongo:

  1. Right click on collection.
  2. Select 'insert Document'.
    enter image description here
  3. Paste your json data
  4. Click validate.
  5. Click save.

Upvotes: 15

toddg
toddg

Reputation: 2906

For anyone wishing to use mongoimport with a remote db (@andi-giga), here's what I did to make it work:

mongoimport -h  xxx.mlab.com --port 2700  -d db_name -c collection_name -u user_name -p password  --type json --file  /Path/to/file.json

Arguments should be self-explanatory.

-h hostname

More information at this link

Upvotes: 7

Deck Pope
Deck Pope

Reputation: 231

if this is not a bson, and only json, you can use mongoimport --jsonArray . refference Insert json file into mongodb

Upvotes: 3

Related Questions