How to load .js

Hello,
I am following through the couse in chapter 2 and I have come to a brick wall where I can not load the .js

I am not using the windows default path setting as it was not possible to set it initially, therefore running the following lines but can not load the .js file

This is what I am doing in Windows cmd

C:\Work\MongoDB\University\M001\loadMovieDetailsDataset>“C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe” loadMovieDetailsDataset.js
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“c6270908-4dac-44f7-b602-ab610232dec0”) }
MongoDB server version: 4.0.6

please note that the output for the following line is as shown below which indicates that he .js file does indeed exist

C:\Work\MongoDB\University\M001\loadMovieDetailsDataset>dir
Volume in drive C is OS
Volume Serial Number is somenumber

Directory of C:\Work\MongoDB\University\M001\loadMovieDetailsDataset

21/03/2019 20:29 .
21/03/2019 20:29 …
21/03/2019 20:29 1,381,666 loadMovieDetailsDataset.js
1 File(s) 1,381,666 bytes
2 Dir(s) 167,071,686,656 bytes free

Agree i see the file in that dir
Why don’t you connect to mongo as shown below and load the file instead of running from command line?What error you are getting while running from command line
I don’t see any error.It says connecting to mongo

MongoDB Enterprise Cluster0-shard-0:PRIMARY> load(“loadMovieDetailsDataset.js”)
true

I did what you said but it gives the message below:
MongoDB Enterprise Cluster0-shard-0:PRIMARY> load(“loadMovieDetailsDataset.js”)
2019-03-24T19:41:03.991+0000 E QUERY [js] SyntaxError: illegal character @(shell):1:5
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

please note that as I mentioned before I am not able to set windows path so to go to the bin directory I have to do this:
cd C:\Program Files\MongoDB\Server\4.0\bin
and then .js file is in directory:
C:\Work\MongoDB\University\M001\loadMovieDetailsDataset

It says syntax error
Did you cut & paste the command or typed it?
Please use double quotes around .js file.When you paste from doc it will appear as inverted commas and command fails

Which version of Windows you are using
setting PATH is not difficult.It was given in lectures i think

Windows 10 and Windows 8

  1. In Search, search for and then select: System (Control Panel)
  2. Click the Advanced system settings link.
  3. Click Environment Variables. …
  4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable.
    If you are not comfortable continue with full path method

C:\Work\MongoDB\University\M001\loadMovieDetailsDataset>“C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe”
Once connected to mongo load the file

Unfortunately I get this message saying that it failed to load because it does not exist:
C:\Program Files\MongoDB\Server\4.0\bin>mongo c:\mongodb\university\m001\loadmoviedetailsdataset\loadMovieDetailsDataset.js
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“38dc7de0-8dd3-427f-8755-24ed11c2a5bc”) }
MongoDB server version: 4.0.6
2019-03-25T06:01:57.119+0000 E - [main] file [c:\mongodb\university\m001\loadmoviedetailsdataset\loadMovieDetailsDataset.js] doesn’t exist
failed to load: c:\mongodb\university\m001\loadmoviedetailsdataset\loadMovieDetailsDataset.js

please note that the file does indeed exists as I do this check below
C:\Work\MongoDB\University\M001\loadMovieDetailsDataset>dir
Volume in drive C is OS
Volume Serial Number is 90A8-D82E

Directory of C:\work\MongoDB\University\M001\loadMovieDetailsDataset

21/03/2019 20:29 .
21/03/2019 20:29 …
21/03/2019 20:29 1,381,666 loadMovieDetailsDataset.js
1 File(s) 1,381,666 bytes
2 Dir(s) 167,099,682,816 bytes free

Please double check
You are giving wrong path

failed to load: c:\mongodb\university…
Your file is at c:\work/mongodb…

:>cd C:\Program Files\MongoDB\Server\4.0\bin

C:\Program Files\MongoDB\Server\4.0\bin>mongo C:\Work\MongoDB\University\M001\loadMovieDetailsDataset\loadMovieDetailsDataset.js
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“1527ff73-63b2-4ee2-8e15-97960431b558”) }
MongoDB server version: 4.0.6

C:\Program Files\MongoDB\Server\4.0\bin>

Then I connect to cluster as indicated in course:
So I type:
mongo “mongodb+srv://cluster9-booxz.mongodb.net/test” --username m001-student --password m001-mongodb-basics

Then I type the command as shown to get list of existing databases
MongoDB Enterprise Cluster9-shard-0:PRIMARY> show dbs
admin 0.000GB
local 1.458GB
MongoDB Enterprise Cluster9-shard-0:PRIMARY>

Question:
At this point, which is the next section in the course, what do I type to load the .js into the cluster?
I type the following

MongoDB Enterprise Cluster9-shard-0:PRIMARY> load(“C:\Work\MongoDB\University\M001\loadMovieDetailsDataset\loadMovieDetailsDataset.js”)

but it gives error as
Error: error loading js file: C:WorkMongoDBUniversityM001loadMovieDetailsDatasetloadMovieDetailsDataset.js

Any suggestions please?

Thank you

Are you still facing issues with this?
Someone suggested that it works with without .js extension
or
load(“C:\Work\MongoDB\University\M001\loadMovieDetailsDataset\loadMovieDetailsDataset.js”)

If nothing works easiest would be to copy the .js file to your mongo bin directory and then run the load from there

All fixed for now.
Chapter 2 completed.
Thank you

Hi
I tried doing in both way from bin directory and from different folder also. I’m getting same error.

Stack trace:
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.drop@src/mongo/shell/collection.js:707:1
@loadMovieDetailsDataset.js:2:1
@(shell):1:1

2019-04-11T11:13:09.994+0530 E QUERY [js] Error: error loading js file: loadMovieDetailsDataset.js @(shell):1:1
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

please help me out

If i do show dbs it gives me a list of all this database.
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show dbs
100YWeatherSmall 0.128GB
admin 0.000GB
aggregations 0.067GB
citibike 0.367GB
city 0.002GB
config 0.000GB
coursera-agg 0.083GB
local 1.089GB
mflix 0.449GB
results 0.000GB
ships 0.001GB
video 0.513GB
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

but in compass i won’t able to see any of this from sandbox cluster, help me out.

First thing
Please check if you are connected to correct cluster or not
Class cluster and sandbox cluster are different
I think you are supposed to load into your sandbox

cd to the dir where file resides
connect to mongo
then load
MongoDB Enterprise Cluster0-shard-0:PRIMARY> load(“loadMovieDetailsDataset.js”)
true
should get above for successful load

2 Likes

Thank You so much i finally loaded .js file to sandbox cluster.

Thank you so much! I did not cd to he dir where js file resides so I could not load it and got an error message. Now problem solved.