Replacing Documents
In this section, you will learn how you can completely replace the documents in a collection.
Sometimes you may want to replace an incorrectly inserted document in a collection. Or consider that, often, the data stored in documents is changed over time. Or, perhaps, to support your product's new requirements, you may want to alter the way your documents are structured or change the fields in your documents. In all such cases, you will need to replace the documents.
In the previous section, we used a new database of CH05
which we will continue using in this section. In the same database, create a collection named users
and insert a few users into it, as follows:
> db.users.insertMany([ {"_id": 2, "name": "Jon Snow", "email": "Jon.Snow@got.es"}, {"_id": 3, "name": "Joffrey Baratheon", "email": "Joffrey.Baratheon@got.es...