Top 10 MongoDB Basic Commands: A Complete Guide with Examples

Mongodb basic commands
Top 10 mongodb basic commands: a complete guide with examples 6

MongoDB Basic Commands with Examples :

Start/Stop MongoDB :

systemctl start mongod
systemctl stop mongod

Check Status of Mongodb:

systemctl status mongod

Output :

Image 1
Top 10 mongodb basic commands: a complete guide with examples 7

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
Top 10 mongodb basic commands: a complete guide with examples 8

Create Collections in a Database:

Syntax :
db.createCollection("collection_name", options)
Example :
db.createCollection("new york")
Image 2
Top 10 mongodb basic commands: a complete guide with examples 9

Drop Collection :

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

Output :

Image 4
Top 10 mongodb basic commands: a complete guide with examples 10

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 :

Spread the love

Leave a Comment

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

Scroll to Top