Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoimport json file syntax

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
like image 689
Archana Mundaye Avatar asked Feb 02 '16 12:02

Archana Mundaye


People also ask

How do I import a JSON file into Mongoimport?

To import JSON file you need to follow the following steps: Step 1: Open a command prompt and give command mongod to connect with MongoDB server and don't close this cmd to stay connected to the server. Step 2: Open another command prompt and run the mongo shell. Using the mongo command.

How do I import data into Mongoimport?

If you have CSV files (or TSV files - they're conceptually the same) to import, use the --type=csv or --type=tsv option to tell mongoimport what format to expect. Also important is to know whether your CSV file has a header row - where the first line doesn't contain data - instead it contains the name for each column.

What is Mongoimport?

The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport , or potentially, another third-party export tool. Run mongoimport from the system command line, not the mongo shell.

Can we insert JSON into MongoDB?

The process to import JSON into MongoDB depends on the operating system and the programming language you are using. However, the key to importing is to access the MongoDB database and parsing the file that you want to import. You can then go through each document sequentially and insert into MongoDB.


1 Answers

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.

like image 141
Akshay Seth Avatar answered Oct 12 '22 01:10

Akshay Seth