Skip to content

Commit 21696f9

Browse files
Merge pull request #3 from Meg528/patch-4
Update 1-WHERE.mdx
2 parents e601ed2 + 83223da commit 21696f9

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

docs/40-CRUD/1-WHERE.mdx

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# 👐 WHERE → .find()
22

3-
Similar to SQL's `WHERE` clause, the `.find()` method in MongoDB retrieves documents from a collection that match a specified query.
3+
Similar to SQL's `WHERE` clause, the `.find()` method in MongoDB retrieves documents from a collection that matches a specified query.
44

55
## Syntax
66

77
```js
88
db.collection.find({ <query> })
99
```
1010

11-
- `<query>`: Specifies conditions to filter documents.
11+
- `<query>`: Specifies conditions to filter documents
1212

1313
## Example: Find all books from 2020
1414

1515
```js
1616
db.books.find({ year: 2020 });
1717
```
1818

19-
### Equivalent SQL Query
19+
### Equivalent SQL query
2020

2121
```sql
2222
SELECT * FROM books WHERE year = 2020;
@@ -26,24 +26,24 @@ SELECT * FROM books WHERE year = 2020;
2626

2727
The `find()` method takes a document as its first argument. This document specifies the filter criteria. You can use a variety of expressions within the filter document:
2828

29-
- **Comparison Operators:** `$eq` (equals), `$ne` (not equals), `$gt` (greater than), `$lt` (less than), `$gte` (greater than or equals), `$lte` (less than or equals), `$in` (in an array), `$nin` (not in an array).
30-
- **Logical Operators:** `$and`, `$or`, `$not`.
31-
- **Element Operators:** `$exists` (check for field existence), `$type` (check data type).
32-
- **Evaluation Operators:** `$regex` (regular expression matching), `$where` (JavaScript code execution).
33-
- **Geo-spatial Operators:** For location-based queries.
34-
- **Array Operators:** For querying arrays.
29+
- **Comparison operators:** `$eq` (equals), `$ne` (not equals), `$gt` (greater than), `$lt` (less than), `$gte` (greater than or equals), `$lte` (less than or equals), `$in` (in an array), `$nin` (not in an array)
30+
- **Logical operators:** `$and`, `$or`, `$not`
31+
- **Element operators:** `$exists` (check for field existence), `$type` (check data type)
32+
- **Evaluation operators:** `$regex` (regular expression matching), `$where` (JavaScript code execution)
33+
- **Geo-spatial operators:** For location-based queries
34+
- **Array operators:** For querying arrays
3535

3636
Now, let's utilize a few MongoDB operators and create more sophisticated queries:
3737

38-
### $or and $gt operator
38+
### $or and $gt operators
3939

40-
Suppose, we want to get all the books written in 2010 OR has more than 200 pages.
40+
Suppose we want to get all the books written in 2010 OR books that have more than 200 pages.
4141

4242
```sql
4343
SELECT * FROM books WHERE year = 2010 OR pages > 200
4444
```
4545

46-
Equivalent MongoDB Query:
46+
Equivalent MongoDB query:
4747

4848
```js
4949
db.books.find({
@@ -56,7 +56,7 @@ db.books.find({
5656

5757
### $and operator
5858

59-
This time, instead of OR let's query using AND:
59+
This time, instead of OR, let's query using AND:
6060

6161
```sql
6262
SELECT * FROM books WHERE year = 2010 AND pages > 200
@@ -75,17 +75,17 @@ db.books.find({
7575

7676
### Shorthand $and
7777

78-
When we are querying on 2 different fields and want to utilize $and, we can do so by passing a document with all the conditions like this:
78+
When we are querying on two different fields and want to utilize $and, we can do so by passing a document with all the conditions, like this:
7979

8080
```js
8181
db.books.find({ year: 2010, pages: { $gt: 200 } });
8282
```
8383

84-
As you can see, we don't have to pass an Array of conditions, MongoDB implicitly considers this as $and.
84+
As you can see, we don't have to pass an array of conditions. MongoDB implicitly considers this as $and.
8585

8686
## 👐 Challenge
8787

88-
Now, translate the following into a MongoDB Query.
88+
Now, translate the following into a MongoDB query.
8989

9090
#### 1. Find all books where `totalInventory` is exactly 5.
9191

@@ -109,7 +109,7 @@ Now, translate the following into a MongoDB Query.
109109
</div>
110110
</details>
111111

112-
#### 3. Find books in the "Science" genre that has more than 300 pages.
112+
#### 3. Find books in the "Science" genre that have more than 300 pages.
113113

114114
<details>
115115
<summary>Answer</summary>

0 commit comments

Comments
 (0)