Objective of this Blog is to build some next level understanding about mongodb find() method. find() method is to query the mongodb collections, similar to select statement in RDBMS Databases, and it return the documents asked for in selection criteria.
Blog will cover below topics:
1. Comparison Query Operators
2. Logical Query Operators
3. MongoDB projections
4. Sort and limit methods
List of Comparison Operators along with description:
- $eq- Matches values that are equal to a specified value.
- $gt- Matches values that are greater than a specified value.
- $gte- Matches values that are greater than or equal to a specified value.
- $in- Matches any of the values specified in an array.
- $lt- Matches values that are less than a specified value.
- $lte- Matches values that are less than or equal to a specified value.
- $ne- Matches all values that are not equal to a specified value.
- $nin- Matches none of the values specified in an array.
List of Logical Operators along with description:
- $and-Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.
- $not-Inverts the effect of a query expression and returns documents that do not match the query expression.
- $nor-Joins query clauses with a logical NOR returns all documents that fail to match both clauses.
- $or-Joins query clauses with a logical OR returns all documents that match the conditions of either clause.
So let's start with the examples:
In my previous blog I have created collection EMP, in this blog will refer the same collection for different operation.
1. $eq: Matches values that are equal to a specified value.
2. $gt: Matches values that are greater than a specified value.
3. $gte: Matches values that are greater than or equal to a specified value.
4. $in- Matches any of the values specified in an array.
5. $lt- Matches values that are less than a specified value.
6. $lte- Matches values that are less than or equal to a specified value.
7. $ne- Matches all values that are not equal to a specified value.
8. $nin- Matches none of the values specified in an array.
9. find() with range of values: query operators can be combined to define a range of conditions.
10. $and: Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.
11. $or: Joins query clauses with a logical OR returns all documents that match the conditions of either clause.
12. MongoDB find() projections: MongoDB projections are basically display of selective fields.
- specifying the fields: displays fields that are given value as 1
13. sort() : orders output documents in ascending or descending way based on key column.
14. limit() : restricts the output documents displayed to user.
15. Function chaining:
functions can be chained or nested to perform multiple operations on documents.
We have explored query operations in little detail. There is lot more to explore in MongoDB and will cover more concepts related to DB operations in coming blogs.
I hope I am able to hit the point and would be anxiously waiting for your response.
In case of any query kindly reach out to me @: vivekchaudhary.90@gmail.com
Thanks to Readers.
Comments
Post a Comment