Cannot import mongodb
Asked Answered
P

8

20

I tried mongo import like this

  1. mongoimport -d test -c foo importfile.json
  2. mongoimport --host localhost --db local --collection lecturer --type json --file temp.json --headerline --upsert

and I've got same error message "Syntax Error: missing ; before statement (shell):1" what's wrong with my code & how to import if my data stored in C:\Documents and Settings\User\Desktop ?? please help, thank's in advance

Pulpit answered 14/6, 2012 at 22:0 Comment(1)
Closely related and probably covered by https://mcmap.net/q/524106/-how-do-i-export-dump-mongodb-databaseAntimissile
N
90

mongoimport is intended to run in command prompt and not in the mongo shell. Try exiting out of the shell and running the command.

Noles answered 15/6, 2012 at 1:40 Comment(5)
I already tried run in command prompt like this below? http://i1066.photobucket.com/albums/u415/zack_syah/commandprompt.png what's wrong and command prompt doesn't recognize syntax? Can you show the step how import with image so I can understandPulpit
"mongoimport is not recognized as a command" means that mongoimport.exe is not in your current path. The ./ syntax with forward path separators is for unix; Windows uses \. Assuming c:\mongodb\bin is where you have saved the MongoDB files, you should be able to run from the c:\mongodb\bin\dump directory using either the full path to mongoimport: c:\mongodb\bin\mongoimport.exe -d test -c foo importfile.bson ...or the relative path: ..\mongoimport.exe -d test -c foo importfile.bson.Crappie
omg. this is also true if you're trying to setup an mlab connection, for anyone else stuck here. geez, thanks!Connoisseur
how do you pass in creds with this? I'm getting 'unauthorized' when I try to import otherwiseSalubrious
@Pulpit jesus dude, I sepnt over one hour looking for why i couldnt import the file and I was trying to do it from the shell. I cant believe there was no documentation stating that this command is supposed to be run from CMD. Thanks for the help bro you da real MVPPulse
O
3

One solution is:

First, in cmd, change to the directory containing mongoexport.exe file, then type your command.

C:\Program Files\MongoDB\Server\3.2\bin> .\mongoexport.exe -d foo -c bar -o output.json
Oxime answered 5/3, 2016 at 12:5 Comment(0)
L
3

mongoimport is to be run on the terminal and not inside the mongo shell. To run mongoimport in terminal, you will need to install the same. On ubuntu, you can do : apt-get install mongo-tools Hope this helps :)

Lutz answered 15/6, 2018 at 9:45 Comment(0)
E
2

I had the same problem and was able to figure it out after a brief struggling and googling. 1. Navigate to the bin directory in command prompt (cd c:..\bin) 2. Run the mongoimport command but you have to specify the full path of your json file. That solves the problem

Ectophyte answered 12/12, 2015 at 22:54 Comment(0)
L
1

try to use CSV is a good.

mongoimport -d mydb -c things --type csv --file locations.csv --headerline --upsert

You can convert by ms excel.

Lento answered 29/3, 2013 at 2:15 Comment(0)
B
0

Open the "Mongo/Server/3.4/bin" folder of mongo db in another command window and try again.It Will work.

Brandt answered 5/6, 2017 at 5:58 Comment(0)
D
0

Open a new terminal or command prompt within the location of the file you want to import and it should work. It will not work on MongoDB shell

Digester answered 2/6, 2019 at 5:50 Comment(0)
S
0

1.) Download the MongoDB Database Tools from MongoDB official Website and Unzip the folder

Mongoimport.exe path

2.) Copy the json file which contains the data to be imported in the same folder as mongoimport.exe

3.) For Windows open the command prompt and run cd (path to folder with mongoimport.exe)

4.) run command .\mongoimport.exe import_data.json -d database_name -c collection_name --jsonArray

example import successful

Selfmade answered 20/3, 2023 at 5:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.