[go: up one dir, main page]

0% found this document useful (0 votes)
24 views1 page

Mongo DB

The document outlines essential operations for managing databases and collections in a database system. It includes commands for creating databases and collections, inserting, querying, updating, deleting documents, and dropping collections and databases. Each operation is accompanied by example commands for clarity.
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)
24 views1 page

Mongo DB

The document outlines essential operations for managing databases and collections in a database system. It includes commands for creating databases and collections, inserting, querying, updating, deleting documents, and dropping collections and databases. Each operation is accompanied by example commands for clarity.
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
You are on page 1/ 1

Database and Collection Operations:

1. Create a Database:

To create a database, use the use command followed by the name of the database. For example:

use mydatabase

2. Create a Collection:

 Collections are created automatically when you insert data into them. You can also
explicitly create a collection using the db.createCollection() method. For example:

db.createCollection("mycollection")

3. Insert Documents:

 To insert documents into a collection, use the insertOne() or insertMany() methods.


For example:

db.mycollection.insertOne({ name: "John", age: 30 })

4. Query Documents:

 Use the find() method to query documents in a collection. For example:

db.mycollection.find()

5. Update Documents:

 To update documents, use the updateOne() or updateMany() methods. For


example:

db.mycollection.updateOne({ name: "John" }, { $set: { age: 35 } })

6. Delete Documents:

 To delete documents, use the deleteOne() or deleteMany() methods. For example:

db.mycollection.deleteOne({ name: "John" })

7. Drop a Collection:

 To drop (delete) a collection, use the drop() method. For example:

db.mycollection.drop()

8. Drop a Database:

 To drop (delete) a database, use the dropDatabase() method. Be cautious, as this


operation deletes the entire database and all its collections. For example:

db.dropDatabase()

You might also like