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# $setEquals
@@ -28,61 +28,123 @@ The `$setEquals` operator returns `true` if two sets have the same distinct elem
2828| --- | --- |
2929| ` array1, array2, ... ` | Arrays to compare for equality. You can specify two or more arrays. |
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" : " 26afb024-53c7-4e94-988c-5eede72277d5" ,
38- "name" : " First Up Consultants | Microphone Bazaar - South Lexusland" ,
39- "sales" : {
40- "totalSales" : 83865 ,
41- "salesByCategory" : [
42- {
43- "categoryName" : " Lavalier Microphones" ,
44- "totalSales" : 44174
45- },
46- {
47- "categoryName" : " Wireless Microphones" ,
48- "totalSales" : 39691
49- }
50- ]
51- },
52- "promotionEvents" : [
53- {
54- "eventName" : " Price Cut Spectacular" ,
55- "discounts" : [
56- {
57- "categoryName" : " Condenser Microphones" ,
58- "discountPercentage" : 5
59- },
60- {
61- "categoryName" : " Dynamic Microphones" ,
62- "discountPercentage" : 14
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
6347 }
64- ]
6548 },
66- {
67- "eventName" : " Bargain Bonanza" ,
68- "discounts" : [
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" : [
6967 {
70- "categoryName" : " Streaming Microphones" ,
71- "discountPercentage" : 14
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+ ]
72103 },
73104 {
74- "categoryName" : " Microphone Stands" ,
75- "discountPercentage" : 14
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+ ]
76140 }
77- ]
78- }
79- ]
141+ ]
80142}
81143```
82144
83145### Example 1: Compare discount categories between events
84146
85- The following example helps you determine if two promotion events offer discounts on the same categories.
147+ This query determines if two promotion events offer discounts on the same categories.
86148
87149``` javascript
88150db .stores .aggregate ([
@@ -103,27 +165,29 @@ db.stores.aggregate([
103165])
104166```
105167
106- The query output compares the discount categories and returns ` false ` , because the values don't match .
168+ This query returns the following result .
107169
108170``` json
109- {
110- "_id" : " 26afb024-53c7-4e94-988c-5eede72277d5" ,
111- "name" : " First Up Consultants | Microphone Bazaar - South Lexusland" ,
112- "event1Categories" : [
113- " Condenser Microphones" ,
114- " Dynamic Microphones"
115- ],
116- "event2Categories" : [
117- " Streaming Microphones" ,
118- " Microphone Stands"
119- ],
120- "sameDiscountCategories" : false
121- }
171+ [
172+ {
173+ "_id" : " 26afb024-53c7-4e94-988c-5eede72277d5" ,
174+ "name" : " First Up Consultants | Microphone Bazaar - South Lexusland" ,
175+ "event1Categories" : [
176+ " Condenser Microphones" ,
177+ " Dynamic Microphones"
178+ ],
179+ "event2Categories" : [
180+ " Streaming Microphones" ,
181+ " Microphone Stands"
182+ ],
183+ "sameDiscountCategories" : false
184+ }
185+ ]
122186```
123187
124188### Example 2: Compare staff requirements
125189
126- The following example determines if two stores have the same staff structure requirements.
190+ This query determines if two stores have the same staff structure requirements.
127191
128192``` javascript
129193db .stores .aggregate ([
@@ -151,28 +215,30 @@ db.stores.aggregate([
151215])
152216```
153217
154- The query returns a value of ` true ` , because both stores have the same staff structure .
218+ This query returns the following result .
155219
156220``` json
157- {
158- "_id" : null ,
159- "store1" : {
160- "_id" : " 26afb024-53c7-4e94-988c-5eede72277d5" ,
161- "name" : " First Up Consultants | Microphone Bazaar - South Lexusland"
162- },
163- "store2" : {
164- "_id" : " f2a8c190-28e4-4e14-9d8b-0256e53dca66" ,
165- "name" : " Fabrikam, Inc. | Car Accessory Outlet - West Adele"
166- },
167- "staffTypes1" : [" fullTime" , " partTime" ],
168- "staffTypes2" : [" fullTime" , " partTime" ],
169- "sameStaffStructure" : true
170- }
221+ [
222+ {
223+ "_id" : null ,
224+ "store1" : {
225+ "_id" : " 26afb024-53c7-4e94-988c-5eede72277d5" ,
226+ "name" : " First Up Consultants | Microphone Bazaar - South Lexusland"
227+ },
228+ "store2" : {
229+ "_id" : " f2a8c190-28e4-4e14-9d8b-0256e53dca66" ,
230+ "name" : " Fabrikam, Inc. | Car Accessory Outlet - West Adele"
231+ },
232+ "staffTypes1" : [" fullTime" , " partTime" ],
233+ "staffTypes2" : [" fullTime" , " partTime" ],
234+ "sameStaffStructure" : true
235+ }
236+ ]
171237```
172238
173239### Example 3: Compare sets with duplicates
174240
175- The following example demonstrates that ` $setEquals ` ignores duplicates and order.
241+ This query uses the ` $setEquals ` operator to ignore duplicates and order.
176242
177243``` javascript
178244db .stores .aggregate ([
@@ -193,16 +259,18 @@ db.stores.aggregate([
193259])
194260```
195261
196- The query returns ` true ` because both of the arrays list the same products in a different sequence, with duplicates .
262+ This query returns the following result .
197263
198264``` json
199- {
200- "_id" : " 26afb024-53c7-4e94-988c-5eede72277d5" ,
201- "name" : " First Up Consultants | Microphone Bazaar - South Lexusland" ,
202- "array1" : [" Microphones" , " Stands" , " Microphones" , " Accessories" ],
203- "array2" : [" Stands" , " Accessories" , " Microphones" ],
204- "arraysEqual" : true
205- }
265+ [
266+ {
267+ "_id" : " 26afb024-53c7-4e94-988c-5eede72277d5" ,
268+ "name" : " First Up Consultants | Microphone Bazaar - South Lexusland" ,
269+ "array1" : [" Microphones" , " Stands" , " Microphones" , " Accessories" ],
270+ "array2" : [" Stands" , " Accessories" , " Microphones" ],
271+ "arraysEqual" : true
272+ }
273+ ]
206274```
207275
208276## Related content
0 commit comments