Real-world data is rarely flat! This tutorial shows you how to perform CRUD (Create, Read, Update, Delete) operations on nested documents (embedded objects) and arrays within your MongoDB collections.
What you will learn:
Dot Notation: The secret to accessing nested data.
How to query a nested field (e.g., db.users.find({ "address.city": "New York" })).
How to update a single nested field using $set (e.g., db.users.updateOne({ ... }, { $set: { "address.zipcode": "10002" } })).
Array Update Operators:
$push: How to add a new item to the end of an array (e.g., add a new comment or tag).
$pull: How to remove an item from an array based on its value (e.g., remove a specific tag).
Positional Operator ($): How to update a specific element inside an array that you found with your query.
Example ($push a new hobby): db.users.updateOne({ name: "Alice" }, { $push: { hobbies: "swimming" } })
Example ($pull a hobby): db.users.updateOne({ name: "Alice" }, { $pull: { hobbies: "reading" } })
#MongoDB #Database #NoSQL #Programming #HowTo #TechTips #MongoDBTutorial