Key Concepts

Review core concepts you need to learn to master this subject

The _id Field

The _id field is assigned to each document as a unique identifier.

By default when inserting a new document into a collection, if you don’t specify an _id field, then MongoDB will automatically generate a unique ObjectId and assign it as the value for that document’s _id field.

CRUD II: Inserting and Updating
Lesson 1 of 2
  1. 1
    By this point, we’ve learned the fundamentals of querying data in MongoDB. In this lesson, we’ll learn how to insert new documents, and update existing ones. As you continue to work with documents…
  2. 2
    Now that we know how MongoDB identifies each individual document, let’s focus on the Create aspect of CRUD operations. Specifically, how do we start adding new documents to our collections? In …
  3. 3
    We have just used .insertOne() to insert a single document into a collection, but what if we want to insert multiple documents into a collection? Here’s where the MongoDB [.insertMany()](https://ww…
  4. 4
    Now that we have explored a few Create operations, let’s look at operations that Update data. In MongoDB, we can use the [.updateOne()](https://www.mongodb.com/docs/manual/reference/method/db….
  5. 5
    While updating a single document using a single field is helpful, MongoDB also stores data inside of embedded documents. So, what if we want to update a specific field in an embedded document? Cons…
  6. 6
    MongoDB provides different array update operators that we can use with the .updateOne() method. In the earlier exercises, we learned to use the $set operator to replace a value. In this exercise, w…
  7. 7
    In the previous exercises, we looked at different ways to update and insert data into a collection. Now, we’ll learn about combining both operations using [upsert](https://www.mongodb.com/docs/manu…
  8. 8
    So far, we have learned how to insert and update individual documents in a collection, but what if we want to update multiple documents simultaneously? This is where the MongoDB [.updateMany()](htt…
  9. 9
    In MongoDB, sometimes we may want to update a document but also return the document we modified. The [.findAndModify()](https://www.mongodb.com/docs/manual/reference/method/db.collection.findAndMod…
  10. 10
    Great job! We’ve covered numerous topics regarding creating and updating documents in collections. Let’s recap some key takeaways from this lesson: - The _id field is a unique identifier for docum…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo