Follow these steps to initialize MongoDB and create a new database called mean-db:
- First we will need to start the MongoDB process locally, so we can connect to it. This process will need to remain running for all the sections of this chapter:
mongod
- This will spawn a new live process in our terminal for mongoDB. We can watch this process to see events and updates sent to MongoDB. In another terminal, we can enter the MongoDB shell:
mongo
- This will bring up a command prompt for MongoDB that we can use to send commands to it. We will use this shell to create a new database for our project. The use command will tell Mongo this is the name of the database we want to work with. By providing a new database name to MongoDB, we will create a new database once we insert a document into it:
use mean-db
- By default, MongoDB doesn't create the database until it stores some sort of record within it. Let's create a simple test post record in our mean-db database:
db.posts.insert({"title":"Learning MongoDB"})
- We can confirm that our mean-db database exists by querying for all the databases within MongoDB:
show dbs