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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

using Mongo

So let's say for a simple example I have the database seed file from the Mongo Basics course which contains the DB name and the data which is then queried, managed updated in the Mongo shell.

Currently I have 2 locations where I'm currently attempting to run a Mongo project.

In once location I've gone a directory deeper than the data/db path

C:\data\db\Mongo-Projects\treehouse-mongo-basics

In there is the seed file.

So I then go to the Mongo shell and type

show dbs

And there's my database as created in my seed file.

var db = db.getSiblingDB('mongoBasics');

I can go into my project there and run any commands I want, right?

But then I go to my other location.

/c/users/pc2/documents/mongo/mongo-test

There's nothing there at the moment except an npm log file but I think I can start and run Mongo projects from here. If I go back into the Mongo shell from this location here and run show dbs again I get the same databases listed.

local        0.000GB
mongoBasics  0.000GB

The default local database and the mongoBasics database. How does this work? Is it best practice to store databases at a root folder in the c:/ or does mongo pick up on databases but still let you access them from any location?

2 Answers

You would start the Mongo daemon (mongod.exe) with the --dbpath option to use a data directory other than the default. Make sure you use the full path.

See the MongoDB documentation:

Or this StackOverflow question:

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Thanks :)

I have a feeling though I'll be using the default location going forward. --dbpath isn't working for me.

Also I've been trying to follow this tutorial http://mongoosejs.com/docs/index.html to get something working on local host but no joy. But never mind that's for another thread :)

The Building a MEAN Application course covers the use of Mongoose.