Skip to content

Commit d30d329

Browse files
authored
Merge pull request #2982 from abinav2307/geospatial-third-pass-validation
Geospatial third pass validation
2 parents c720cfd + 47139f8 commit d30d329

File tree

11 files changed

+1356
-82
lines changed

11 files changed

+1356
-82
lines changed

articles/cosmos-db/mongodb/vcore/operators/geospatial/$box.md

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: suvishod
77
ms.service: azure-cosmos-db
88
ms.subservice: mongodb-vcore
99
ms.topic: language-reference
10-
ms.date: 07/25/2025
10+
ms.date: 09/04/2025
1111
---
1212

1313
# $box
@@ -16,8 +16,6 @@ The `$box` operator defines a rectangular area for geospatial queries using two
1616

1717
## Syntax
1818

19-
The syntax for the `$box` operator is as follows:
20-
2119
```javascript
2220
{
2321
<location field>: {
@@ -39,9 +37,121 @@ The syntax for the `$box` operator is as follows:
3937
| `lower_left`| An array of [longitude, latitude] specifying the bottom-left corner |
4038
| `upper_right`| An array of [longitude, latitude] specifying the top-right corner |
4139

42-
## Example
40+
## Examples
41+
42+
Consider this sample document from the stores collection.
43+
44+
```json
45+
{
46+
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
47+
"name": "First Up Consultants | Beverage Shop - Satterfieldmouth",
48+
"location": {
49+
"lat": -89.2384,
50+
"lon": -46.4012
51+
},
52+
"staff": {
53+
"totalStaff": {
54+
"fullTime": 8,
55+
"partTime": 20
56+
}
57+
},
58+
"sales": {
59+
"totalSales": 75670,
60+
"salesByCategory": [
61+
{
62+
"categoryName": "Wine Accessories",
63+
"totalSales": 34440
64+
},
65+
{
66+
"categoryName": "Bitters",
67+
"totalSales": 39496
68+
},
69+
{
70+
"categoryName": "Rum",
71+
"totalSales": 1734
72+
}
73+
]
74+
},
75+
"promotionEvents": [
76+
{
77+
"eventName": "Unbeatable Bargain Bash",
78+
"promotionalDates": {
79+
"startDate": {
80+
"Year": 2024,
81+
"Month": 6,
82+
"Day": 23
83+
},
84+
"endDate": {
85+
"Year": 2024,
86+
"Month": 7,
87+
"Day": 2
88+
}
89+
},
90+
"discounts": [
91+
{
92+
"categoryName": "Whiskey",
93+
"discountPercentage": 7
94+
},
95+
{
96+
"categoryName": "Bitters",
97+
"discountPercentage": 15
98+
},
99+
{
100+
"categoryName": "Brandy",
101+
"discountPercentage": 8
102+
},
103+
{
104+
"categoryName": "Sports Drinks",
105+
"discountPercentage": 22
106+
},
107+
{
108+
"categoryName": "Vodka",
109+
"discountPercentage": 19
110+
}
111+
]
112+
},
113+
{
114+
"eventName": "Steal of a Deal Days",
115+
"promotionalDates": {
116+
"startDate": {
117+
"Year": 2024,
118+
"Month": 9,
119+
"Day": 21
120+
},
121+
"endDate": {
122+
"Year": 2024,
123+
"Month": 9,
124+
"Day": 29
125+
}
126+
},
127+
"discounts": [
128+
{
129+
"categoryName": "Organic Wine",
130+
"discountPercentage": 19
131+
},
132+
{
133+
"categoryName": "White Wine",
134+
"discountPercentage": 20
135+
},
136+
{
137+
"categoryName": "Sparkling Wine",
138+
"discountPercentage": 19
139+
},
140+
{
141+
"categoryName": "Whiskey",
142+
"discountPercentage": 17
143+
},
144+
{
145+
"categoryName": "Vodka",
146+
"discountPercentage": 23
147+
}
148+
]
149+
}
150+
]
151+
}
152+
```
43153

44-
Using the `stores` collection, let's find stores within a rectangular region:
154+
### Example 1 - Find stores within a rectangular region
45155

46156
```javascript
47157
db.stores.find(
@@ -62,9 +172,10 @@ db.stores.find(
62172
).limit(2)
63173
```
64174

65-
This query returns all stores that fall within the rectangular region defined by these coordinates.
175+
The first two results returned by this query are:
66176

67177
```json
178+
[
68179
{
69180
"_id": "923d2228-6a28-4856-ac9d-77c39eaf1800",
70181
"name": "Lakeshore Retail | Home Decor Hub - Franciscoton",
@@ -81,8 +192,10 @@ This query returns all stores that fall within the rectangular region defined by
81192
"lon": 0.6784
82193
}
83194
}
195+
]
84196
```
85197

86198
## Related content
87199

88200
[!INCLUDE[Related content](../includes/related-content.md)]
201+

articles/cosmos-db/mongodb/vcore/operators/geospatial/$center.md

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,123 @@ The `$center` operator specifies a circle using legacy coordinate pairs to be us
3232
| `<y>` | The y-coordinate of the circle's center point |
3333
| `<radius>` | The radius of the circle in the same units as the coordinates |
3434

35-
## Example
35+
## Examples
3636

37-
Let's find all stores within a 50-degree radius of 'First Up Consultants Microphone Bazaar' using our `stores` dataset.
37+
Consider this sample document from the stores collection.
38+
39+
```json
40+
{
41+
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
42+
"name": "First Up Consultants | Beverage Shop - Satterfieldmouth",
43+
"location": {
44+
"lat": -89.2384,
45+
"lon": -46.4012
46+
},
47+
"staff": {
48+
"totalStaff": {
49+
"fullTime": 8,
50+
"partTime": 20
51+
}
52+
},
53+
"sales": {
54+
"totalSales": 75670,
55+
"salesByCategory": [
56+
{
57+
"categoryName": "Wine Accessories",
58+
"totalSales": 34440
59+
},
60+
{
61+
"categoryName": "Bitters",
62+
"totalSales": 39496
63+
},
64+
{
65+
"categoryName": "Rum",
66+
"totalSales": 1734
67+
}
68+
]
69+
},
70+
"promotionEvents": [
71+
{
72+
"eventName": "Unbeatable Bargain Bash",
73+
"promotionalDates": {
74+
"startDate": {
75+
"Year": 2024,
76+
"Month": 6,
77+
"Day": 23
78+
},
79+
"endDate": {
80+
"Year": 2024,
81+
"Month": 7,
82+
"Day": 2
83+
}
84+
},
85+
"discounts": [
86+
{
87+
"categoryName": "Whiskey",
88+
"discountPercentage": 7
89+
},
90+
{
91+
"categoryName": "Bitters",
92+
"discountPercentage": 15
93+
},
94+
{
95+
"categoryName": "Brandy",
96+
"discountPercentage": 8
97+
},
98+
{
99+
"categoryName": "Sports Drinks",
100+
"discountPercentage": 22
101+
},
102+
{
103+
"categoryName": "Vodka",
104+
"discountPercentage": 19
105+
}
106+
]
107+
},
108+
{
109+
"eventName": "Steal of a Deal Days",
110+
"promotionalDates": {
111+
"startDate": {
112+
"Year": 2024,
113+
"Month": 9,
114+
"Day": 21
115+
},
116+
"endDate": {
117+
"Year": 2024,
118+
"Month": 9,
119+
"Day": 29
120+
}
121+
},
122+
"discounts": [
123+
{
124+
"categoryName": "Organic Wine",
125+
"discountPercentage": 19
126+
},
127+
{
128+
"categoryName": "White Wine",
129+
"discountPercentage": 20
130+
},
131+
{
132+
"categoryName": "Sparkling Wine",
133+
"discountPercentage": 19
134+
},
135+
{
136+
"categoryName": "Whiskey",
137+
"discountPercentage": 17
138+
},
139+
{
140+
"categoryName": "Vodka",
141+
"discountPercentage": 23
142+
}
143+
]
144+
}
145+
]
146+
}
147+
```
148+
149+
### Example 1 - Search within a 50-degree radius
150+
151+
Let's find all stores within a 50-degree radius of 'First Up Consultants Microphone Bazaar' using our `stores` dataset. This query retrieves stores within a 50-degree radius of the First Up Consultants Microphone Bazaar location.
38152

39153
```javascript
40154
db.stores.find(
@@ -54,9 +168,10 @@ db.stores.find(
54168
).limit(2)
55169
```
56170

57-
The query returns stores within 50-degree radius of the First Up Consultants Microphone Bazaar location, which could be useful for analyzing market coverage or planning delivery routes.
171+
The first two results returned by this query are:
58172

59173
```json
174+
[
60175
{
61176
"name": "Contoso, Ltd. | Baby Products Corner - Port Jerrold",
62177
"location": { "lat": -72.7709, "lon": -24.3031 },
@@ -67,6 +182,7 @@ The query returns stores within 50-degree radius of the First Up Consultants Mic
67182
"location": { "lat": -64.5509, "lon": -28.7144 },
68183
"city": "Trystanport"
69184
}
185+
]
70186
```
71187

72188
> [!IMPORTANT]
@@ -79,3 +195,4 @@ The query returns stores within 50-degree radius of the First Up Consultants Mic
79195
## Related content
80196

81197
[!INCLUDE[Related content](../includes/related-content.md)]
198+

0 commit comments

Comments
 (0)