For the first part you will need to setup MongoDB 2.6+ using Homebrew in Mac OS X and second configure a database for building a REST API using NodeJS on a local machine. The second part should be similar for Linux and Windows with exceptions to the dbpath, mongod.conf, and mongo.log locations.
You will need to have Homebrew installed. To learn how to install Homebrew read the Homebrew Wiki.
Once you have Homebrew installed. Open a terminal window and enter the following:
Once MongoDB has finished installing openand make a note where the default database is going to be located for future reference, the . You will need this location later. Of course you can change the location to anywhere else.
In the following next steps you will need two (2) terminal windows open.
- In one terminal window enter (note that the port is an optional parameter, the default port is 27017). If you changed the path in dbpath, changed it below:
- In the second terminal window enter . This give you access to the database. If you enter in mongo, it will list database name: admin (empty).
- Next enter the following to create the database administrator user for the admin database:
To quit mongo enter either or press control + c.
- Now go back to the first terminal window and press control + c to terminate mongod. Then start mongod again by entering:
- Now it is time to add a user and to create a new database:
For more on db.createUser see MongoDB db.createUser()
- Afterwards it should have created a new user and a database called mydb. You can test it out by doing:
It should display.
You can also use Robomongo (Mac OS X, Windows, Linux) to check if the database has correct information stored.
Reference: Getting Started with MongoDB