Select documents that match the nested field β
In this example, we are retrieving the documents that match the specified nested field.
python
db.Courses.find({"courseDetails.name": "Java Backend Development"}).pretty() |
MongoDB β Query Embedded Documents Using Mongo Shell
MongoDB provides you read operations to retrieve embedded/nested documents from the collection or query a collection for a embedded/nested document. You can perform read operations using the db.collection.find() method. This method selects or views embedded/nested documents of the collection and returns the cursor to the selected document.
Syntax: db.collection.find(filter, projection)
Parameters:
- filter: It is an optional parameter. It specifies the selection filter with the help of query operators. And if you want to get all the documents present in the collection, then omit these parameters or pass an empty document in the method. The type of this parameter is a Document.
- projection: It is an optional parameter. It specifies that only those fields return to the document that matches the given query filter. And if you want to get all the fields in the document, then omit this parameter.
Return: This method returns a cursor to the documents that match the specified query criteria. When you use find() method, it returns documents, which means the method is actually returning the cursor to the documents.
Contact Us