Cannot import mongodb

2019-01-11 22:42发布

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

6条回答
Lonely孤独者°
2楼-- · 2019-01-11 23:30

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

查看更多
一夜七次
3楼-- · 2019-01-11 23:31

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
查看更多
Rolldiameter
4楼-- · 2019-01-11 23:33

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

查看更多
5楼-- · 2019-01-11 23:37

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.

查看更多
【Aperson】
6楼-- · 2019-01-11 23:38

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

查看更多
看我几分像从前
7楼-- · 2019-01-11 23:45

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

查看更多
登录 后发表回答