Running mongo shell and loading Chapter 1 Homework js files from mongo121 directory

I’ve installed MongoDB on my “C” drive, but I want to create the “m121” directory for this course on my “D” drive.
I have noticed that mongo shell has to be run from it’s native directory, but how do I load the validateLab1.js file that’s located on my “D” drive? Navigating with “cd” command doesn’t seem to work on the terminal.
I’ve tried using the Load command and pasting the absolute path of the JS file but it didn’t work as well.
The screenshot below yields the same error while trying to use the path on my “D” drive for the JS file.
I’m using Windows 10 if that matters, thanks in advance :grinning:

Hello @111511, welcome to the MongoDB Community forum!

You can try the Windows file path with \\ as separator:

load("C:\\Program Files\\MongoDB\\Server\\4.4\\bin\\m121\\validateLab1.js")


Thank you for your answer, it solved my problem ! Do you happen to know why is using \ as separator doesn’t work ?

I think the \ (the backslash) character has a special meaning and you “escape” it using a backslash to be interpreted as a backslash when used as a file path separator.

Optionally, you can use this (and it works fine):

load("C:/Program Files/MongoDB/Server/4.4/bin/m121/validateLab1.js")

Also, see String Literal - Escape Sequences


I see, that is probably because my computer language isn’t English, so maybe it had set paths with backslash in order to sync with my computer’s language. Thanks again !

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.