NoSQL_MongoDB_Tutorial_Final
NoSQL_MongoDB_Tutorial_Final
SQL vs Compliance
BSON vs
Example:
JSON
JSON: { "name": "Ali", "age": 30 }
NoSQL
• **updateOne(), updateMany()** –
Modifies existing documents.
1 2 3
Download and Install Set
install MongoShell environment
MongoDB variables
Using MongoShell
SQL: NoSQL:
I NSERT INTO users (name, age) db.users.insertOne({ name: "Ali", age:
VALUES ('Ali', 30); 30 })
Data Types
db.products.insertOne({ name:
Example: "Laptop", price: 1500, tags:
["electronics", "gadget"] })
{ acknowledged: true,
Expected Result: insertedId: ObjectId('...') }
Sorting and Limiting
Documents
• Expected Result:
– [ {name: "Bilal", age: 28}, {name:
"Ali", age: 30} ]
SQL vs NoSQL - Find
SQL: NoSQL:
SELECT * FROM users WHERE age > 25; db.users.find({ age: { $gt: 25 } })
Update Documents
NoSQL:
• db.users.updateOne({ name: "Ali" },
{ $set: { age: 35 } })
Expected Result:
• { matchedCount: 1, modifiedCount: 1 }
SQL vs NoSQL - Update
SQL: NoSQL:
UPDATE users SET age = 35 WHERE name = db.users.updateOne({ name: "Ali" }, { $set:
'Ali'; { age: 35 } })
Delete Documents
NoSQL:
Expected Result:
• { deletedCount: 1 }
SQL vs NoSQL - Delete
db.users.deleteOne({ name:
NoSQL: "Bilal" })
Comparison Operators
Example:
Expected Result:
• Expected Result:
– { "createdCollectionAutomatically": false,
"numIndexesBefore": 1, "numIndexesAfter": 2 }
Collections
• Collections = Tables in SQL
• Create:
– db.createCollection("orders")
• Expected Result:
– { "ok": 1 }
Conclusion