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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Using load() with Mongo

hello :)

Just a quick question with the load command in MongoDB,

I had a lot of trouble when following the video trying to connection to seed.js, probably because I'm working in a different setup to a Mac.

Then I remembered about the data/db directory and placed my project in there.

load('/data/db/Mongo-Projects\treehouse-mongo-basics/seed.js')

It worked, and I was able to run commands on it.

But it never worked unless I placed the seed file in that directory even though it looked liked Huston was able to run commands from other locations.

Why is this? I know we're looking for relative paths from the current working directory, but that's different from just the data/db directory.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

And another question in case anyone finds this thread.... when loading the seed.js file I find Huston takes up some data when using the show db's command, but when I do it comes up as 0.0000gb for both databases.

This suggests to me that no data has been loaded... yet I'm still able to load queries and methods from it. Odd.

3 Answers

I know this conversation is rather old, but I got stuck with this, so in case someone else is using Windows and is stuck...

In my case, it wouldn't load the file when I used the load('full_path_to_file') as suggested above, however, after I exited all the folders and then used cd('path_to_file_folder') and then load('file'), it actually loaded it.

make sure to (" ") use double quotation marks. it does make a differences.

OH!!!! and all the slash marks have to be ( / )

failed

> cd('C:/Users/kayvon's family/treehouse-mongo-basics')
2019-01-07T13:57:38.886-0600 E QUERY    [js] SyntaxError: missing ) after argument list @(shell):1:20

accepted

> cd("C:/Users/kayvon's family/treehouse-mongo-basics")
> ls()
[ "./.git/", "./README.md", "./seed.js" ]
> load("./seed.js")
true
>

I got it to work by just putting in the absolute file path. ex: load('C:/projectfolder/seed.js')

I think in the video he changes the directory he is in, but he does it very fast. (FYI - I am working on windows through ConEmu)

Luke Gresser
Luke Gresser
10,449 Points

I was stuck with the same problem and I tried your solution and it worked! Thank you!

Kjetil-Lennart A. Lorentzen
Kjetil-Lennart A. Lorentzen
13,390 Points

I didn't get anything to work, i copy pasted the absolute path from windows explorer. BUT! When i changed all the "\" to "/" it worked. I did like ieva graudule, cd('e:/the/directory') then load('seed.js')

I hope this helps someone