Skip to content

Update 2-SELECT.mdx #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/40-CRUD/2-SELECT.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In SQL, the `SELECT` statement allows us to specify which columns to retrieve fr
db.collection.find({ <query> }, { projection })
```

## **Projection Basics**
## **Projection basics**

- By default, MongoDB returns all fields in a document.
- Use projection to **include (1)** or **exclude (0)** specific fields.
Expand All @@ -21,7 +21,7 @@ db.collection.find({ <query> }, { projection })
db.books.find({}, { title: 1, authors: 1, _id: 0 });
```

**Equivalent SQL Query:**
**Equivalent SQL query:**

```sql
SELECT title, authors FROM books;
Expand All @@ -40,7 +40,7 @@ Here:
db.books.find({}, { reviews: 0 });
```

**Equivalent SQL Query:**
**Equivalent SQL query:**

```sql
SELECT title, authors, genres, totalInventory, available FROM books;
Expand All @@ -52,13 +52,13 @@ Here:

---

## **Example 3: Using Projection along with a Query**
## **Example 3: Using projection along with a query**

```js
db.books.find({ genres: "Science" }, { title: 1, totalInventory: 1, _id: 0 });
```

**Equivalent SQL Query:**
**Equivalent SQL query:**

```sql
SELECT title, totalInventory FROM books WHERE genres='Science';
Expand Down