MongoDB is a NoSQL database that features a flexible document-based structure. MongoDB queries work on collections, returning the documents that match the query criteria.
Queries in MongoDB MongoDB executes queries through the find() method that returns data from a collection. The querying mechanism depends on various factors: indexes, query filters, projection, and sorting.
Example: Querying a Collection Let's assume we have a students collection with the following documents:
{ "_id": 1, "name": "Ram", "age": 22, "department": "CSE", "marks": 85 },
{ "_id": 2, "name": "Nidhi", "age": 23, "department": "ECE", "marks": 78 },
{ "_id": 3, "name": "Rahul", "age": 21, "department": "CSE", "marks": 90 },
{ "_id": 4, "name": "Sonia", "age": 22, "department": "ME", "marks": 88 }
]