0% found this document useful (0 votes)
388 views3 pages

MongoDb Commands

This document outlines various commands for interacting with databases, collections, and documents in MongoDB. It includes commands for viewing and managing databases and collections, as well as inserting, updating, searching, and deleting documents. Common document operations like finding, limiting, counting, updating, renaming, and sorting documents are also demonstrated.

Uploaded by

Pranjal tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
388 views3 pages

MongoDb Commands

This document outlines various commands for interacting with databases, collections, and documents in MongoDB. It includes commands for viewing and managing databases and collections, as well as inserting, updating, searching, and deleting documents. Common document operations like finding, limiting, counting, updating, renaming, and sorting documents are also demonstrated.

Uploaded by

Pranjal tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MongoDb Commands

1. Database Commands
View all databases
show dbs

Create a new or switch databases


use dbName

View current Database


db

Delete Database
[Link]()
2. Collection Commands
Show Collections
show collections

Create a collection named 'comments'


[Link]('comments')

Drop a collection named 'comments'


[Link]()
3. Row(Document) Commands
Show all Rows in a Collection
[Link]()
Show all Rows in a Collection (Prettified)
[Link]().pretty()
Find the first row matching the object
[Link]({name: 'MERN'})
Insert One Row
[Link]({
'name': 'MERN',
'lang': 'JavaScript',
'member_since': 5
})
Insert many Rows
[Link]([{
'name': 'GFG',
'lang': 'JavaScript',
'member_since': 5
},
{'name': 'Ninja',
'lang': 'Python',
'member_since': 3
},
{'name': 'JDKPoint',
'lang': 'Java',
'member_since': 4
}])

Search in a MongoDb Database


[Link]({lang:'Python'})
Limit the number of rows in output
[Link]().limit(2)
Count the number of rows in the output
[Link]().count()
Update a row
[Link]({name: 'GFG NOIDA'},
{$set: {'name': 'GFG',
'lang': 'JavaScript',
'member_since': 51
}}, {upsert: true})
Mongodb Increment Operator
[Link]({name: 'Ninja2'},
{$inc:{
member_since: 2
}})

Mongodb Rename Operator


[Link]({name: 'Ninja'},
{$rename:{
member_since: 'member'
}})
Delete Row
[Link]({name: 'Ninja'})
Less than/Greater than/ Less than or Eq/Greater than or Eq
[Link]({member_since: {$lt: 90}})
[Link]({member_since: {$lte: 90}})
[Link]({member_since: {$gt: 90}})
[Link]({member_since: {$gte: 90}})

[Link]().sort({member_since:-1}).pretty()

You might also like