Load command is failing while loading people.json file

I tried to load people.json file on my cluster and it is failing with below error:

MongoDB Enterprise Cluster0-shard-0:PRIMARY> load(“people.json”)
2019-03-18T23:18:33.415-0500 E QUERY [js] [people.json:1:6] SyntaxError: missing ; before statement
Stack trace:

2019-03-18T23:18:33.426-0500 E QUERY [js] Error: error loading js file: people.json @(shell):1:1

I edited people.json file by adding below 3 lines on the top of file:

db = db.getSiblingDB(“m201”);
db.people.insertMany ( [

and added below line at the end
] ) ;

This time load command failed with below error message:

MongoDB Enterprise Cluster0-shard-0:PRIMARY> load(“people.json”)
2019-03-18T23:19:05.585-0500 E QUERY [js] [people.json:5:0] SyntaxError: missing ] after element list
Stack trace:

2019-03-18T23:19:05.594-0500 E QUERY [js] Error: error loading js file: people.json @(shell):1:1

What is the mistake I am doing here ?


Did not have to edit any file during my labs
Used mongoimport to load the .json files

The file people.json is not a file that you load in the mongo shell. The instructions indicate to use mongorestore to upload the data into the cluster.

Thanks for your reply. I could load the data from Compass directly using import option. I will try mongorestore as well.

However, can you please tell me what is the difference between the .js file and .json file provided ?
Does load command support only .js file ?

Files with .js are normally application code written in JavaScript.

Files with .json are normally data file containing documents in the Java Script Object Notation.

Thanks Steeve,

If I look at the .json file and .js files (provided during Mongodb classes) I do not see much of a difference in them.

.js file has extra 3 lines in the beginning and one at the end which I tried to put in .json and it did not work with load.

I suspect that you did not read the links I posted. Otherwise you would have no that the 2 are really really not the same. One is code and the other is data. There is no way you can convert data by adding a few lines here and there.

But some .js has some .json in it. But you cannot change one into the other.

1 Like