0% found this document useful (0 votes)
700 views11 pages

MongoDB Notes

MongoDB is a database that stores data in collections instead of tables. It stores data in documents instead of rows, with documents made up of key-value pairs instead of defined columns. The three main operations shown are inserting documents into collections, searching collections, and updating documents.

Uploaded by

Gitanshu Kumar
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)
700 views11 pages

MongoDB Notes

MongoDB is a database that stores data in collections instead of tables. It stores data in documents instead of rows, with documents made up of key-value pairs instead of defined columns. The three main operations shown are inserting documents into collections, searching collections, and updating documents.

Uploaded by

Gitanshu Kumar
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

MongoDB

➢ Table----------Collection
➢ Row-----------documents
➢ Columns-----fields
➢ Database----Database
➢ BSON
➢ View all database: show dbs
➢ Db--- current database

➢ Create/switch database: use “database_name”

➢ Drop database: [Link]()


➢ View all collection: show collections

➢ Create a new collection: [Link](“<collection_name>”)

➢ Delete collection: db.<collection_name>.drop()

➢ Inserting a document:
db.<collection_name>.insert(
{
“key”: “value”
}
)

Or

➢ Inserting many documents:


db.<collection_name>.insertMany(
[
{}
{}
]
)

Or, we can also use some JavaScript predefined function.


➢ View all documents:

db.<collection_name>.find();

Or
db.<collection_name>.find().pretty();

➢ Search for a document:


db.<collection_name>.find(
{
key: “value”
}
)
➢ Limiting the output:
db.<collection_name>.find().limit(<integer>)

➢ Counting the output:


db.<collection_name>.find().count()

Or ,

➢ Sorting the collections:


db.<collection_name>.find().sort({key:-1})
1:Ascending, -1:Descending
Or
➢ Updating the document:
db.<collection_name>.updateone(
{search},
{$set:{updated object}}
{upsert:boolean}
)
Upsert: Create the record if does not exist.
Upsert: Create the record if does not exist.

➢ Update operators:
$rename
***There are so many update operators***
➢ Delete document
db.<collection_name>.remove({search})

You might also like