How to do it...

Follow these steps to initialize MongoDB and create a new database called mean-db:

  1. 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
  1. 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
  1. 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 
  1. 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"})
  1. We can confirm that our mean-db database exists by querying for all the databases within MongoDB:
show dbs
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.251.217