Skip to content

Commit 81b8c15

Browse files
authored
Merge pull request #2990 from abinav2307/set-expression-third-pass-validation
Set expression third pass validation
2 parents 863441a + 8797eed commit 81b8c15

File tree

7 files changed

+666
-405
lines changed

7 files changed

+666
-405
lines changed

articles/cosmos-db/mongodb/vcore/operators/set-expression/$allelementstrue.md

Lines changed: 112 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ms.service: azure-cosmos-db
88
ms.subservice: mongodb-vcore
99
ms.topic: language-reference
10-
ms.date: 08/03/2025
10+
ms.date: 09/04/2025
1111
---
1212

1313
# $allElementsTrue
@@ -28,70 +28,123 @@ The `$allElementsTrue` operator evaluates an array as a set. It returns `true` i
2828
| --- | --- |
2929
| `array` | An array of expressions to evaluate. If the array is empty, `$allElementsTrue` returns `true`. |
3030

31-
## Example
31+
## Examples
3232

33-
Let's understand the usage with sample JSON from the `stores` dataset.
33+
Consider this sample document from the stores collection.
3434

3535
```json
3636
{
37-
"_id": "2cf3f885-9962-4b67-a172-aa9039e9ae2f",
38-
"name": "First Up Consultants | Bed and Bath Center - South Amir",
39-
"location": {
40-
"lat": 60.7954,
41-
"lon": -142.0012
42-
},
43-
"staff": {
44-
"totalStaff": {
45-
"fullTime": 18,
46-
"partTime": 17
47-
}
48-
},
49-
"sales": {
50-
"totalSales": 37701,
51-
"salesByCategory": [
52-
{
53-
"categoryName": "Mattress Toppers",
54-
"totalSales": 37701
55-
}
56-
]
57-
},
58-
"promotionEvents": [
59-
{
60-
"eventName": "Price Drop Palooza",
61-
"promotionalDates": {
62-
"startDate": {
63-
"Year": 2024,
64-
"Month": 9,
65-
"Day": 21
66-
},
67-
"endDate": {
68-
"Year": 2024,
69-
"Month": 9,
70-
"Day": 30
37+
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
38+
"name": "First Up Consultants | Beverage Shop - Satterfieldmouth",
39+
"location": {
40+
"lat": -89.2384,
41+
"lon": -46.4012
42+
},
43+
"staff": {
44+
"totalStaff": {
45+
"fullTime": 8,
46+
"partTime": 20
7147
}
72-
},
73-
"discounts": [
74-
{
75-
"categoryName": "Bath Accessories",
76-
"discountPercentage": 18
77-
},
48+
},
49+
"sales": {
50+
"totalSales": 75670,
51+
"salesByCategory": [
52+
{
53+
"categoryName": "Wine Accessories",
54+
"totalSales": 34440
55+
},
56+
{
57+
"categoryName": "Bitters",
58+
"totalSales": 39496
59+
},
60+
{
61+
"categoryName": "Rum",
62+
"totalSales": 1734
63+
}
64+
]
65+
},
66+
"promotionEvents": [
7867
{
79-
"categoryName": "Pillow Top Mattresses",
80-
"discountPercentage": 17
68+
"eventName": "Unbeatable Bargain Bash",
69+
"promotionalDates": {
70+
"startDate": {
71+
"Year": 2024,
72+
"Month": 6,
73+
"Day": 23
74+
},
75+
"endDate": {
76+
"Year": 2024,
77+
"Month": 7,
78+
"Day": 2
79+
}
80+
},
81+
"discounts": [
82+
{
83+
"categoryName": "Whiskey",
84+
"discountPercentage": 7
85+
},
86+
{
87+
"categoryName": "Bitters",
88+
"discountPercentage": 15
89+
},
90+
{
91+
"categoryName": "Brandy",
92+
"discountPercentage": 8
93+
},
94+
{
95+
"categoryName": "Sports Drinks",
96+
"discountPercentage": 22
97+
},
98+
{
99+
"categoryName": "Vodka",
100+
"discountPercentage": 19
101+
}
102+
]
81103
},
82104
{
83-
"categoryName": "Bathroom Scales",
84-
"discountPercentage": 9
105+
"eventName": "Steal of a Deal Days",
106+
"promotionalDates": {
107+
"startDate": {
108+
"Year": 2024,
109+
"Month": 9,
110+
"Day": 21
111+
},
112+
"endDate": {
113+
"Year": 2024,
114+
"Month": 9,
115+
"Day": 29
116+
}
117+
},
118+
"discounts": [
119+
{
120+
"categoryName": "Organic Wine",
121+
"discountPercentage": 19
122+
},
123+
{
124+
"categoryName": "White Wine",
125+
"discountPercentage": 20
126+
},
127+
{
128+
"categoryName": "Sparkling Wine",
129+
"discountPercentage": 19
130+
},
131+
{
132+
"categoryName": "Whiskey",
133+
"discountPercentage": 17
134+
},
135+
{
136+
"categoryName": "Vodka",
137+
"discountPercentage": 23
138+
}
139+
]
85140
}
86-
]
87-
}
88-
]
141+
]
89142
}
90143
```
91144

92-
### Example: Determine if all the discount percentages are higher than zero
145+
### Example 1: Determine if all the discount percentages are higher than zero
93146

94-
The aggregation query determines if all the discount percentages in each promotion event are greater than zero.
147+
This query determines if all the discount percentages in each promotion event are greater than zero.
95148

96149
```javascript
97150
db.stores.aggregate([
@@ -115,13 +168,15 @@ db.stores.aggregate([
115168
])
116169
```
117170

118-
The query shows whether all discount percentages are greater than zero.
171+
This query returns the following result.
119172

120173
```json
121-
{
122-
"_id": "2cf3f885-9962-4b67-a172-aa9039e9ae2f",
123-
"allDiscountsValid": true
124-
}
174+
[
175+
{
176+
"_id": "2cf3f885-9962-4b67-a172-aa9039e9ae2f",
177+
"allDiscountsValid": true
178+
}
179+
]
125180
```
126181

127182
## Related content

0 commit comments

Comments
 (0)