Skip to content

Update 40-search-inside-objects-in-arrays.mdx #58

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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-using-arrays/40-search-inside-objects-in-arrays.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# 👐 Searching inside Objects in arrays
# 👐 Searching Inside Objects in Arrays

In our books, we're using the [Attribute Pattern](https://www.mongodb.com/developer/products/mongodb/attribute-pattern/) to have different attributes in our documents. As we can see in the [sample doc](/docs/simple-queries/project), we have an `attributes` array, containing several objects, each with the same structure:

Expand Down Expand Up @@ -38,7 +38,7 @@ attributes: [

## Matching object fields, the simplest way

How do we search for all the books that have an msrp of 9.99? We want books that, inside `attributes`, have an object with key `msrp` and value `9.99`?
How do we search for all the books that have an MSRP of 9.99? We want books that, inside `attributes`, have an object with key `msrp` and value `9.99`?

<Tabs groupId="aggregations">
<TabItem value="atlas" label="Atlas UI">
Expand All @@ -62,7 +62,7 @@ db.books.aggregate([
</TabItem>
</Tabs>

Above example is using the shorthand $and operator, that we can also explicitly write:
The above example is using the shorthand $and operator, that we can also explicitly write:

<Tabs groupId="aggregations">
<TabItem value="atlas" label="Atlas UI">
Expand All @@ -87,7 +87,7 @@ db.books.aggregate([
</Tabs>


Find all the books with an MSPR of 9.99 and that have been reprinted (hint: `edition` is `Reprint`)
Find all the books with an MSPR of 9.99 and that have been reprinted (hint: `edition` is `Reprint`):

<details>
<summary>Answer</summary>
Expand Down Expand Up @@ -194,7 +194,7 @@ db.books.aggregate([
</Tabs>


Here we're getting a copy of each book for each object inside the `$attributes` array. This "flattens" the array and returns many copies of the same documents, one for each different attribute that we have.
Here, we're getting a copy of each book for each object inside the `$attributes` array. This "flattens" the array and returns many copies of the same documents, one for each different attribute that we have.

👐 To better understand `$unwind`, run this aggregation.

Expand Down