0% found this document useful (0 votes)
5 views8 pages

MongoDB Shell Command Reference Guide

Uploaded by

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

MongoDB Shell Command Reference Guide

Uploaded by

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

Mongo shell commands

[Link] -> To start mongo compiler.

2.
show dbs -> To show the list off all database.
3.
db -> To show the current using database.

4.
show collec ons -> To show the list of collec ons.
{Note : (For next command) If the collec on does not exist
mongoDB automa cally create it}.
5.
[Link] [Link]({name:"adam",
age:"10"}) ->It will add single document in
collec on.

6.
[Link] onName.find() -> To show the all data of
your collec on.
7.
[Link] [Link]([{name:"adam",
age:"10"},{name:"rock", age:"19"}]) ->It will add
mul ple document in collec on.

8.
[Link] onName.findOne(key:value) -> To find
and show the one require data of your collec on.
9.
We can use different type of logical operator with
find. read this for that all things –

To learn more queries and logical operator visit-


Query and Projec on Operators - MongoDB Manual v7.0
10.
[Link] [Link](<filter>,<upda on
>,<op on>) –> To update data in collec on.

For more visit ->


Update Operators - MongoDB Manual v7.0
11.
[Link] [Link](<filter>,<upda o
n>,<op on>) -> it will update the all user with
given condi on.
12.
[Link] [Link](<filter>,<op on>) ->
it will delet the user with given condi on.

13.
[Link] [Link](<filter>,<op on>) -
> it will delet the all us er with given condi on.

Common questions

Powered by AI

To retrieve a specific document based on a key-value pair in MongoDB, you can use the command db.collectionName.findOne(key:value).

To update multiple documents in a MongoDB collection that meet specific criteria, use db.collectionName.updateMany(<filter>,<update>,<option>).

The 'show collections' command in MongoDB displays all collections in the current database, whereas 'show dbs' lists all available databases .

The db.collectionName.deleteMany() method deletes all documents in a collection that match the specified condition .

db.collectionName.insertOne() is used to add a single document to a collection, while db.collectionName.insertMany() is used to add multiple documents at once .

To update a single document in a MongoDB collection, you would use the updateOne method with the syntax db.collectionName.updateOne(<filter>,<update>,<option>). This command updates the first document matching the filter .

In MongoDB, if you try to insert a document into a non-existing collection, the collection is automatically created .

You would use the db command in the MongoDB shell to display the current database you are using .

To find documents in a MongoDB collection that satisfy a logical condition, you can use the find() method with logical operators. These operators allow you to define complex queries by combining multiple conditions. For more details, you can refer to the MongoDB Manual on Query and Projection Operators .

You would use the command db.collectionName.insertOne({name:"value", key:"value"}) to add an initial document to a new collection. This operation implies that even if the collection doesn't exist, MongoDB will automatically create it when the first document is inserted .

You might also like