Querying in MongoDB
This section will show the use of the sample_mflix.movies
collection as an example for demonstration. Working with real data with some expected query results helps reinforce the acquired notions and makes understanding the underlying processes easier and more thorough.
The most frequent MongoDB query language commands—and the ones that this chapter will be covering—are as follows:
find()
: Finds and selects documents matching simple or complex criteriainsertOne()
: Inserts a new document into the collectioninsertMany()
: Inserts an array of documents into the collectionupdateOne()
andupdateMany()
: Update one or more documents according to some criteriadeleteOne()
anddeleteMany()
: Delete one or more documents from the collection
There are 21,349 documents in the sample_mflix.movies
collection. To query for all the documents, type the following command in the MongoDB Shell:
db.movies.find()
The preceding command...