mongoimport json file syntax

44,836

Solution 1

You are probably running this command under mongo shell. As you can see in the path program files/mongodb/server/3.2/bin there is no command under mongod as mongoimport. So in order to solve the problem, navigate your cmd prompt to the file and without using mongo shell(mongo) run the command in cmd prompt.

Solution 2

I was trying to use mongoimport from mongo shell. So answer is "mongoimport is different utility" so if you want to use mongoimport then after starting mongo server using "mongod", use need to start different cmd and go to C:\Program Files\MongoDB\Server\3.2\bin or it should be in ur path and then u need to run "mongoimport" command. If you start using "mongoimport" from "mongo" shell then it will not work.

Solution 3

mongoimport is different utility so use different command prompt.

Solution 4

mongoimport command

Try the following steps in the given manner:

Step1. On new command prompt, cd to location of mongo's bin directory. for example:

cd c:\MongoDB\bin

Step2. Run the following command:

mongoimport --db test --collection restaurants --file location/of/jsonfile

Solution 5

try like this. copy past this code in text document and save it with .sh extension. place both the files on desktop and execute .sh file in terminal

mongoimport --db test --collection students --file students.json
Share:
44,836
Author by

Archana Mundaye

Updated on May 05, 2021

Comments

  • Archana Mundaye over 1 year

    I'm trying to import json document using mongoimport command and have tried all possible ways but it's giving be below error. Plz tell me what m I doing wrong here. I've given full path of json doc. I want to import big document having 800+ records but because it failing so currently my students.json contains simple one line {name : "Archana"} but even this is failing.

    C:\data\db>mongo
    2016-02-02T17:48:44.788+0530 I CONTROL  [main] Hotfix KB2731284 or later update is installed, no need to zero-out data
    MongoDB shell version: 3.2.1
    connecting to: test
    > show collections
    names
    students
    > mondoimport -d test -c students students.json
    2016-02-02T17:50:21.001+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:15
    > mondoimport -d test -c students < students.json
    2016-02-02T17:50:25.840+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:15
    > mondoimport -d test -c students < file students.json
    2016-02-02T17:50:31.233+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:15
    > mondoimport -d test -c students < f students.json
    2016-02-02T17:50:35.417+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:15
    > mondoimport -d test -c students < f C:\data\db\students.json
    2016-02-02T17:50:51.658+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:15
    > mondoimport -d test -c students < f "C:\data\db\students.json"
    2016-02-02T17:50:56.897+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:15
    > mondoimport -d test -c students C:\data\db\students.json
    2016-02-02T17:51:06.849+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:15
    > mondoimport -db test -c students C:\data\db\students.json
    2016-02-02T17:54:33.545+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:16
    > mondoimport --db test --collection students C:\data\db\students.json
    2016-02-02T17:56:24.253+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:14
    > mondoimport --db test --collection students --file C:\data\db\students.json
    2016-02-02T17:56:33.589+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:14
    > mondoimport --db test --collection students --file C:\data\db\students.json --jsonArray
    2016-02-02T17:58:21.131+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:14
    > mondoimport --db test --collection students C:\data\db\students.json --jsonArray
    2016-02-02T17:58:32.650+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:14
    
  • Archana Mundaye almost 7 years
    essentially opening in different command prompt as said by Chridam, yes it worked.
  • Owen
    Owen over 6 years
    if the answer is "mongoimport is different utility" then maybe accept the answer where you've literally quoted that from (even if it's your own, and not particularly detailed) instead of leaving this unresolved? Alternatively accept @Akshay's answer, which is more detailed.
  • Winnemucca
    Winnemucca almost 6 years
    how far back did you go on your directory? I am in the root and getting no such file or directory
  • Deepak over 5 years
    Thanks Sebastián Palma
  • Akshay Seth
    Akshay Seth over 4 years
    Mark it as an answer if that helped you