When it comes to managing and manipulating data in a database system, we are bound to create, read, update, and delete (CRUD) documents. We can use MongoDB's CRUD operations for this. You can read more information about MongoDB CRUD operations at https://docs.mongodb.com/manual/crud/. In this book, we will just see a simple example of how we can use each of these:
- The Create operations:
We can use the following methods to create or insert fresh documents to a collection:
db.<collection>.insertOne(<document>)
db.<collection>.insertMany([<document>, <document>, <document>, ...])
Note that if the collection does not exist in your database, these insert operations will create it for you automatically.
- The Read operations:
We can use the following method to fetch documents from a collection:
db.<collection>.find(<query>, <projection>)
- The Update operations:
We can use the following methods to modify...