0
votes

Hello guys I'm trying to import JSON file to my collection in mongodb database but keeps give me an error. how to import this json file? I tried using mongodb compass and mongoshell give me this error

E  QUERY    [js] uncaught exception: SyntaxError: unexpected token: identifier :      
@(shell):1:14

This is the file: https://github.com/pedox/indonesia-mongo/blob/master/indonesia.json

My mongoimport command:

mongoimport --jsonArray --db DB_Pro --collection indonesia --file:C:\Users\<usernamePC>\Downloads\db indonesia\Indonesia-mongo\indonesia.json
2
Use the command-line tool mongoimport to import JSON data in to a MongoDB collection. It is run from the operating system command line / terminal / command prompt. - prasad_
@prasad_I got an error 2020-07-02T11:23:47.375+0700 E QUERY [js] uncaught exception: SyntaxError: unexpected token: identifier : @(shell):1:14 - flyingduck92
Please edit your post and include the mongoimport command you are using. - prasad_
--file:C:\Users\... instead try this: --file="C:\Users\..." - prasad_
@prasad_ lol non sense - flyingduck92

2 Answers

0
votes

Just open the terminal in the folder your .json file is located in. Here is one I do to import the data in Ubuntu.

  1. Open a folder and Open in terminal

  2. Download the file:

    curl -o data.json https://raw.githubusercontent.com/pedox/indonesia-mongo/master/indonesia.json
    
  3. Import the file:

    mongoimport --host=localhost --port=27017 --username=gotqn --collection=trades --db=github --file=data.json --authenticationDatabase admin
    

So, I need to specify the host and the port. Also, because I am using a password to authenticated I need to specify the username and the authenticationDatabase and then enter the password when asked.

Also, as there are various options - check the official docs.

0
votes

Try using Studio3t. it is very user friendly to use MongoDB and provides many functionalities to operate on db and collections