MongoDB is an open-source and leading NoSQL database. In this tutorial, we will learn MongoDB basic commands.
Introduction
MongoDB is very popular NoSQL database. MongoDB stores information in a JSON format but not limited to JSON, you can also store other data formats.
Terminologies
Here is the common MongoDB terminolgies.
- Database – Stores collections
- Collections – similar to tables, store data.
MongoDB Installation
Head over to the official MongoDB installation page and download the MongoDB installer suited for your operating system.
We can verify the installation of MongoDB by running the MongoDB shell. Open your terminal and type mongo command.
Awesome. Moving right along.
Creating database
To create a new database, just type the following command.
You can run this command to validate whether the database was created or not.
Let’s create a collection.
Creating collection
To create a new collection, run the following command.
You can run this command to validate whether the collection was created or not.
Let’s add some data in the collection.
Adding data in the collection
You can use the insert() method to add a new data in the collection.
Awesome. Let’s search for the data we just added.
Finding the data in the collection
You can use the find() method to search for the information inside the collection.
Updating and Deleting data in the collection
You can use update() and delete() method to update or delete the information in the collection.
Summary
We learned the basic commands of MongoDB and how to use them to perform operations in MongoDB.
Further Study
Build a RESTful API using Node and MongoDB
Getting Started With MongoDB Atlas with Node.js