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" } })).

Querying Arrays: How to find documents where an array field contains a specific value (e.g., db.users.find({ hobbies: "reading" })).

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 the first element in an array that matched your query.

Example ($push a new hobby): db.users.updateOne({ name: "Alice" }, { $push: { hobbies: "swimming" } })

Example (Update a nested field): db.users.updateOne({ name: "Alice" }, { $set: { "address.city": "Miami" } })

#MongoDB #Database #NoSQL #Programming #HowTo #TechTips #MongoDBTutorial