Summary
We started this chapter with the creation of documents in a collection. We saw that, during an insert operation, MongoDB creates the underlying collection if it does not exist, and autogenerates an _id
field if the document does not have one already. We then covered various functions provided by MongoDB to delete and replace one or more documents in a collection, as well as the concept of upsert, its benefits, its support in MongoDB, and how an upsert operation differs from delete and insert. Then we learned how to add, update, rename, or remove fields in MongoDB documents using various functions and operators.
In the next chapter, we will execute some complex update commands using the aggregation pipeline support that was added in MongoDB 4.2, and learn how to modify the elements in an array field.