MongoDB Flashcards
What is MongoDB
No SQL or non-relational database
Collection
A group of documents in MongoDB. Do not enforce a rigid schema
Document
a record stored in JSON-like format, and each document in the collection has a different structure
Visualize a collection
db.users({“name”:”Bob”, “age”:30}, {name:”Charlie”, “age”:35, “Hobbies”:[“cycling”,”hiking”]})
Visualize a document
{“name”: “Alicce”, “age”:25}
documents ae stored ({..})
Query using .find()
db.collection.find()
Query with a condition
$gt
db.collection.find({“condition”:{“$gt”:x})
Update a single document in a collection
$set
db.collection.updateOne({“name”:”Alice”},{“$set”:{“age”:26}})
Delete a single document
.deleteOne
db.collection.deleteOne({“name”:”Alice”})
Delete multiple documents
.deleteMany
db.users.deleteMany(“age”:{“$lt”:30}}) // Delets users younger than 30
Delete a collection
.drop()
db.collection.drop()