24

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)?

Varun Sukheja
  • 6,170
  • 5
  • 51
  • 93
user2981029
  • 584
  • 1
  • 5
  • 17
  • 1
    Robomongo — is a shell-centric crossplatform MongoDB management tool. Provides nice GUI – Mayuri Apr 11 '14 at 10:54

9 Answers9

16

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.
Maximilian Ast
  • 3,369
  • 12
  • 36
  • 47
Varun Sukheja
  • 6,170
  • 5
  • 51
  • 93
  • The only problem with this method is how unresponsible the UI becomes when parsing large JSON files. – David Gourde Aug 18 '17 at 17:49
  • 6
    This method create a single document with 500 child parameters, instead create 500 documents... – Bartolomeu S. Gusella Oct 14 '20 at 19:24
  • Just as @BartolomeuS.Gusella said, this inserts only 1 document in the database. In order to add multiple documents, this doesn't work. Probably [this](https://stackoverflow.com/questions/19441228/insert-json-file-into-mongodb?answertab=votes#tab-top) would do it – Zap Dec 04 '20 at 13:48
  • This method does not work for very big collections – KaraNyyan Dec 22 '21 at 09:35
10

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
jsingh
  • 1,256
  • 13
  • 24
user2981029
  • 584
  • 1
  • 5
  • 17
  • Do you know how to import s.th. with Robomongo/ Mac Shell if the database is outside of your local environment. E.g. on a server without accessing the server shell? – Andi Giga Apr 03 '15 at 06:56
  • 1
    @AndiGiga I provided an answer showing how to import to a remotedb – toddg Sep 20 '16 at 21:36
  • 1
    Tried it on windows and it works fine The mongoimport.exe is present in the bin folder where MongoDb is installed. The above answer worked just fine for me.. Just imported a 5 GB Json file. Took some time though – Vishweshwar Kapse Mar 26 '18 at 12:21
7

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

toddg
  • 2,863
  • 2
  • 18
  • 33
5

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)

panzerstadt
  • 53
  • 1
  • 2
  • Note that while you can't comment on answers just yet, you can suggest an edit to a post if you have additional information to add. You can do this by clicking the "edit" link just below the posts' text. – Hoppeduppeanut Aug 26 '20 at 04:37
3

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

Community
  • 1
  • 1
Deck Pope
  • 231
  • 3
  • 10
3

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

Mohd Belal
  • 1,119
  • 11
  • 23
2

Tested :

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

It works very well!

jsingh
  • 1,256
  • 13
  • 24
K78
  • 29
  • 1
  • I would like to point out that I visted the man page to figure out csv files, and this can be done with the --type csv flag in place of --jsonArray – Jason V Apr 28 '20 at 19:31
0

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

0

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

Harsh Patel
  • 6,334
  • 10
  • 40
  • 73