-
Notifications
You must be signed in to change notification settings - Fork 16
How to Create and Setup a Mongo Database
I suggest using a hosted Mongo database. I am most familiar with Compose.io, but there are other options. Compose offers a free sandbox database that is great for toying with, but it is notably slower than the paid option and not suitable for production.
After signing up, follow the directions to create a database and a collection. Our database is called curatedb and our collection is called collections! We currently only have one collection, but you can create more if you need them.
Once your database is up, you'll want to connect your program to it. This is done via connection strings. Navigate to the admin section and you'll find the uri to connect to your database. Username, password, and permissions can be set up under the users tab of the admin panel. Once you have a username and password, plug it into your uri. This is your connection string. It should be kept secret. Save it as an environmental variable on your server and refer to that environmental variable with your program. Never commit it to GitHub.
On our server we saved our connection string as CURATES_DB_URI. To access this in node:
process.env.CURATES_DB_URI
Then, to connect to the server using mongoose:
var mongoose = require('mongoose'); mongoose.connect(process.env.CURATES_DB_URI);
You already know how to do this.