You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/mongodb/vcore/operators/set-expression/$setintersection.md
+44-40Lines changed: 44 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
ms.service: azure-cosmos-db
8
8
ms.subservice: mongodb-vcore
9
9
ms.topic: language-reference
10
-
ms.date: 08/03/2025
10
+
ms.date: 09/04/2025
11
11
---
12
12
13
13
# $setIntersection
@@ -28,9 +28,9 @@ The `$setIntersection` operator returns an array that contains elements that app
28
28
| --- | --- |
29
29
|`<array1>, <array2>, ...`| Two or more arrays to find the intersection of. Each array is treated as a set. |
30
30
31
-
## Example
31
+
## Examples
32
32
33
-
Let's understand the usage with sample JSON from the `stores` dataset.
33
+
Consider this sample document from the stores collection.
34
34
35
35
```json
36
36
{
@@ -160,7 +160,7 @@ Let's understand the usage with sample JSON from the `stores` dataset.
160
160
161
161
### Example 1: Find common categories between sales and promotions
162
162
163
-
The following example helps you determine which product categories appear in a store's sales data and promotion discounts.
163
+
This query determines which product categories appear in a store's sales data and promotion discounts.
164
164
165
165
```javascript
166
166
db.stores.aggregate([
@@ -188,42 +188,44 @@ db.stores.aggregate([
188
188
])
189
189
```
190
190
191
-
The query output shows which categories are common between sales and promotion events.
191
+
This query returns the following result.
192
192
193
193
```json
194
-
{
195
-
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
196
-
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
197
-
"salesCategories": [
198
-
"Sound Bars",
199
-
"Game Controllers",
200
-
"Remote Controls",
201
-
"VR Games"
202
-
],
203
-
"firstPromotionCategories": [
204
-
"DVD Players",
205
-
"Projector Lamps",
206
-
"Media Players",
207
-
"Blu-ray Players",
208
-
"Home Theater Systems",
209
-
"Televisions"
210
-
],
211
-
"secondPromotionCategories": [
212
-
"TV Mounts",
213
-
"Game Accessories",
214
-
"Portable Projectors",
215
-
"Projector Screens",
216
-
"Blu-ray Players",
217
-
"DVD Players"
218
-
],
219
-
"commonSalesAndFirstPromotion": [],
220
-
"commonSalesAndSecondPromotion": []
221
-
}
194
+
[
195
+
{
196
+
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
197
+
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
198
+
"salesCategories": [
199
+
"Sound Bars",
200
+
"Game Controllers",
201
+
"Remote Controls",
202
+
"VR Games"
203
+
],
204
+
"firstPromotionCategories": [
205
+
"DVD Players",
206
+
"Projector Lamps",
207
+
"Media Players",
208
+
"Blu-ray Players",
209
+
"Home Theater Systems",
210
+
"Televisions"
211
+
],
212
+
"secondPromotionCategories": [
213
+
"TV Mounts",
214
+
"Game Accessories",
215
+
"Portable Projectors",
216
+
"Projector Screens",
217
+
"Blu-ray Players",
218
+
"DVD Players"
219
+
],
220
+
"commonSalesAndFirstPromotion": [],
221
+
"commonSalesAndSecondPromotion": []
222
+
}
223
+
]
222
224
```
223
225
224
226
### Example 2: Find common categories across multiple promotion events
225
227
226
-
The following example helps you find categories that appear in multiple promotion events.
228
+
This query fetches categories that appear in multiple promotion events.
227
229
228
230
```javascript
229
231
db.stores.aggregate([
@@ -243,14 +245,16 @@ db.stores.aggregate([
243
245
])
244
246
```
245
247
246
-
The query returns an empty array for `commonAcrossPromotions`, because there are no common product categories that appear across all of the promotions.
248
+
This query returns the following result.
247
249
248
250
```json
249
-
{
250
-
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
251
-
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
252
-
"commonAcrossPromotions": []
253
-
}
251
+
[
252
+
{
253
+
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
254
+
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
0 commit comments