Top 10 MongoDB Basic Commands: A Complete Guide with Examples

Mongodb basic commands

MongoDB Basic Commands with Examples :

Start/Stop MongoDB :

systemctl start mongod
systemctl stop mongod

Check Status of Mongodb:

systemctl status mongod

Output :

Image 1

Connect to MongoDB Shell :

To start using MongoDB, open your terminal and enter the following command:

mongo

Check DB Version :

db.version()

Check Available Databases:

show dbs

Create or Switch to a Database:

use testdb

Check the Current Database:

db

Drop Database :

db.dropDatabase()

Output :

Image

Create Collections in a Database:

Syntax :
db.createCollection("collection_name", options)
Example :
db.createCollection("new york")
Image 2

Drop Collection :

Syntax :
db.collectionName.drop();
Example :
db.test.drop();

Output :

Image 4

Hope this helps that you can get the MongoDB Basic Commands!! Also, you can get more information regarding mongodb commands with examples from the MongoDB Official Documentation as well :

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top