Loading products.json

MongoDB Enterprise > load(“products.json”)
2019-02-16T03:06:49.136+0000 E QUERY [thread1] [products.json:1:6] SyntaxError: missing ; before statement
Stack trace:
@(shell)

I’m trying to load product into my MongoDB and getting above error any idea how to fix this ?
I copied the products.json under /shared

Use mongoimport to create a MongoDB collection from a JSON or CSV file:

load() method works for .js files

3 Likes

mongoimport --port 27000 -u m103-application-user -p m103-application-pass --db “applicationData” products.json

error inserting documents: not authorized on applicationData to execute command { insert: “products”, writeConcern: { getLastError: 1, w: 1 }, ordered: false, $db: “applicationData” }

any idea what might be wrong ?

Try this way

vagrant@m103:/dataset$ mongoimport -u m103-application-user -p m103-application-pass --collection products --authenticationDatabase admin --db applicationData --port 27000 products.json
2019-01-14T18:04:42.131+0000 connected to: localhost:27000
2019-01-14T18:04:45.116+0000 [###…] applicationData.products 12.6MB/87.9MB (14.3%)

2019-01-14T18:05:02.482+0000 [########################] applicationData.products 87.9MB/87.9MB (100.0%)
2019-01-14T18:05:02.482+0000 imported 516784 documents

Please recheck how you created m103-application-user. You should assign readWrite role on applicationData database

1 Like

Are you running the mongoimport from within mongo, is so, then run that command from the vagrant shell. It is run external to mongo.

It is easy to lose track of where you are and run a command from the wrong level.

The error message literally tells you what is wrong :slight_smile: Mahesh has it right: the user account you’re using to load the data does not have the right permissions.

1 Like

May be you should specify on your command line, with an option, that your authentication database is “admin”. Otherwise, you won’t be well authenticated, and so not authorized to access to applicationData.

1 Like