Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Mongo Basics Understanding MongoDB Store Your Blog In Mongo

I don't understand how to load() the js-file

I didn't manage to use the "mongo"-command until I was in C:\Program Files\MongoDB\Server\4.0\bin. Then the shell fired up. How in the world to I find my way to the js-file in the folder treehouse-mongo-basics that i cloned down into C:\Users\Downloads\ to be able to use the load() function in the shell? I feel like I've tried everything,

2 Answers

Alexander Solberg
Alexander Solberg
14,350 Points

I remember having problems with getting load() to work until I wrapped the path in quotes.

Also, I think you're supposed to use forward-slashes "/" for directory indication.

If you haven't allready, try something like this: load('C:/Users/Downloads/script.js')

Yeah I tried all of that. The back-slashes is because my Command Prompt uses back-slashes. But I tried forward too, didn't help. Tried quotes too. Is it because I'm not standing in the right folder or something? Is the "mongo"-command supposed to work anywhere on the whole computer?

Alexander Solberg
Alexander Solberg
14,350 Points

Well it depends on what operating system you're using etc. I am running on Windows 8.1, so in my case, Mongo won't run unless I execute the mongo.exe file from within it's path(by using ./mongo.exe). There are tools out there like Scoop(I think it was called) that enable you to use the "mongo" command from anywhere.

As long as you're in the mongo-shell, and you switched to the database you want to use, then load() should work(if used with quotes, as the path is interpreted as a string). Once in the shell, you should be able to load scripts from anywhere on your computer.

If it's not working then I don't know what else to do sorry :(

Are you getting any error messages btw?