0% found this document useful (0 votes)
3 views5 pages

MongoDB Basic Operations

The document provides a series of MongoDB commands for database management, including creating, dropping, and switching databases, as well as managing collections. It also details operations for inserting, finding, updating, and deleting documents within a collection. Key commands include showing databases, creating collections, and performing CRUD operations on documents.

Uploaded by

moni.shaiva737
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)
3 views5 pages

MongoDB Basic Operations

The document provides a series of MongoDB commands for database management, including creating, dropping, and switching databases, as well as managing collections. It also details operations for inserting, finding, updating, and deleting documents within a collection. Key commands include showing databases, creating collections, and performing CRUD operations on documents.

Uploaded by

moni.shaiva737
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

1) show dbs; -- It shows the already created all databases

2) db; -- shows the current db

3) Switch / Create database

4) [Link](); -- Drop current database

5) show collections; -- show already created collections in DB

6) [Link](“users”); -- to create a collection

7) [Link](); -- to drop a collection


8) [Link]({ name: "Suhel", age: 25 }) – insert one record/doc in collection

9) [Link]([

{ name: "Ali", age: 22 },

{ name: "Khan", age: 28 }

]); -- insert many docs/records

10) [Link](); -- to fetch records/docs

11) [Link]().pretty(); -- formatted printing


12) [Link]({ age: 25 }); -- find with condition

13) [Link]({ name: "Suhel" }); -- find only one doc

14) [Link]({ age: 25 }, { name: 1, _id: 0 }); -- Find with projection

15) [Link]().limit(2); -- Limit results

16) [Link]().sort({ age: 1 }) // 1 = asc, -1 = desc -- Sort the results

17) [Link](

{ name: "Suhel" },

{ $set: { age: 26 } }

); -- update one document


18) [Link](

{ age: { $gt: 25 } },

{ $set: { status: "senior" } }

); -- update many docs/records

19) [Link](

{ name: "Ali" },

{ name: "Ali", age: 23 }

); -- Replace document

20) [Link]({ name: "Ali" }); // Delete one

21) [Link]({ age: { $lt: 25 } }) // Delete Many


22) [Link]({}); // Delete all

You might also like