Full-Stack Web Development with Vue.js and Node

(singke) #1
Introducing MEVN Chapter 1

Once the executable file is downloaded, run the installer and follow the instructions. Just go
through the dialog box, reading the instructions carefully. When the installation is


complete, just click on the Close button and you are done.


Using MongoDB


Let's dive a little deeper into MongoDB. As mentioned earlier as well, Mongo consists of a


database with collections (tables/groups of data) and documents (rows/entries/records). We
will use a few commands provided by MongoDB to create, update, and delete the


documents:


First, start the Mongo server with this command:


$ mongod

Then, open the Mongo shell with this command:


$ mongo

Creating or using a MongoDB database

This is the place where we can see all of our databases, collections, and documents.


To display the list of databases that we have, we can use the following:


> show dbs

Now, this command should list all the existing databases. To use the database that we


want, we can simply run this command:


> use <database_name>

But if there is no database listed, don't worry. MongoDB provides us with a functionality


where, when we run the preceding command, even if that database does not exist, it will
automatically create a database with the given name for us.


So, if we already have a database that we want to use, we simply run that command and, if
there are no databases yet, we create one using this command:


> use posts

When we run this command, a database named posts will be created.

Free download pdf