Skip to content

Commit aa13bbe

Browse files
Merge pull request #2985 from abinav2307/miscellaneous-query-third-pass-validation
Miscellaneous query third pass validation
2 parents e593e0f + 4ebb8ee commit aa13bbe

File tree

3 files changed

+164
-45
lines changed

3 files changed

+164
-45
lines changed

articles/cosmos-db/mongodb/vcore/operators/miscellaneous-query/$comment.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: $comment
3-
titleSuffix: Overview of the $comment operation in Azure Cosmos DB for MongoDB (vCore)
3+
titleSuffix: Overview of the $comment operator in Azure Cosmos DB for MongoDB (vCore)
44
description: The $comment operator adds a comment to a query to help identify the query in logs and profiler output.
55
author: suvishodcitus
66
ms.author: suvishod
77
ms.service: azure-cosmos-db
88
ms.subservice: mongodb-vcore
99
ms.topic: language-reference
10-
ms.date: 02/12/2025
10+
ms.date: 09/04/2025
1111
---
1212

1313
# $comment
@@ -16,10 +16,10 @@ The `$comment` operator adds comments to queries to help identify them in logs a
1616

1717
## Syntax
1818

19-
The syntax for the `$comment` operator is as follows:
20-
2119
```javascript
22-
{ $comment: <string> }
20+
{
21+
$comment: <string>
22+
}
2323
```
2424

2525
## Parameters
@@ -86,7 +86,7 @@ Consider this sample document from the stores collection.
8686
```
8787
### Example 1: Find stores with total sales over 100,000 and add a log comment for reference
8888

89-
To find stores with total sales greater than 100,000 and includes a comment for easy identification in logs.
89+
This query retrieves stores with total sales greater than 100,000 and includes a comment for easy identification in logs.
9090

9191
```javascript
9292
db.stores.find(
@@ -95,18 +95,22 @@ db.stores.find(
9595
).comment("Query to find high-performing stores")
9696
```
9797

98-
Sample Output
98+
This query returns the following result.
9999

100100
```json
101-
{
102-
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
103-
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
104-
"sales": {
105-
"totalSales": 151864
101+
[
102+
{
103+
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
104+
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
105+
"sales": {
106+
"totalSales": 151864
107+
}
106108
}
107-
}
109+
]
108110
```
109111

110112
## Related content
111113

112114
[!INCLUDE[Related content](../includes/related-content.md)]
115+
116+

articles/cosmos-db/mongodb/vcore/operators/miscellaneous-query/$natural.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: $natural
3-
titleSuffix: Overview of the $natural operation in Azure Cosmos DB for MongoDB (vCore)
3+
titleSuffix: Overview of the $natural operator in Azure Cosmos DB for MongoDB (vCore)
44
description: The $natural operator forces the query to use the natural order of documents in a collection, providing control over document ordering and retrieval.
55
author: suvishodcitus
66
ms.author: suvishod
77
ms.service: azure-cosmos-db
88
ms.subservice: mongodb-vcore
99
ms.topic: reference
10-
ms.date: 02/12/2025
10+
ms.date: 09/04/2025
1111
---
1212

1313
# $natural
@@ -16,10 +16,10 @@ The `$natural` operator forces the query to use the natural order of documents i
1616

1717
## Syntax
1818

19-
The syntax for the `$natural` operator in sort operations is as follows:
20-
2119
```javascript
22-
{ $natural: <1 | -1> }
20+
{
21+
$natural: <1 | -1>
22+
}
2323
```
2424

2525
## Parameters
@@ -84,39 +84,41 @@ Consider this sample document from the stores collection.
8484

8585
### Example 1: Basic Natural Order Sorting
8686

87-
To retrieve stores in their natural insertion order:
87+
This query retrieves all stores in the order they were inserted into the collection.
8888

8989
```javascript
90-
db.stores.find({}).sort({ $natural: 1 })
90+
db.stores.find({}).sort({
91+
$natural: 1
92+
})
9193
```
9294

93-
This query returns all stores in the order they were inserted into the collection.
94-
9595
### Example 2: Reverse Natural Order
9696

97-
To retrieve stores in reverse insertion order (most recently inserted first):
97+
This query returns all stores in reverse insertion order, with the most recently added documents appearing first.
9898

9999
```javascript
100-
db.stores.find({}).sort({ $natural: -1 })
100+
db.stores.find({}).sort({
101+
$natural: -1
102+
})
101103
```
102104

103-
This query returns all stores in reverse insertion order, with the most recently added documents appearing first.
104-
105105
### Example 3: Natural Order with Filtering
106106

107-
To find stores with total sales above a certain threshold and sort them in natural order:
107+
This query filters stores with total sales greater than 50,000 and returns them in natural insertion order.
108108

109109
```javascript
110110
db.stores.find({
111-
"sales.totalSales": { $gt: 50000 }
112-
}).sort({ $natural: 1 })
111+
"sales.totalSales": {
112+
$gt: 50000
113+
}
114+
}).sort({
115+
$natural: 1
116+
})
113117
```
114118

115-
This query filters stores with total sales greater than 50,000 and returns them in natural insertion order.
116-
117119
### Example 4: Natural Order with Projection
118120

119-
To retrieve specific fields from stores in natural order:
121+
This query returns only the store name, total sales, and location coordinates in natural insertion order.
120122

121123
```javascript
122124
db.stores.find({}, {
@@ -127,18 +129,16 @@ db.stores.find({}, {
127129
}).sort({ $natural: 1 })
128130
```
129131

130-
This query returns only the store name, total sales, and location coordinates in natural insertion order.
131-
132132
### Example 5: Natural Order with Limit
133133

134-
To get the first three stores that were inserted into the collection:
134+
This query returns the first three stores in their natural insertion order.
135135

136136
```javascript
137-
db.stores.find({}).sort({ $natural: 1 }).limit(3)
137+
db.stores.find({}).sort({
138+
$natural: 1
139+
}).limit(3)
138140
```
139141

140-
This query returns the first three stores in their natural insertion order.
141-
142142
## Use Cases
143143

144144
The `$natural` operator is useful in the following scenarios:
@@ -152,3 +152,4 @@ The `$natural` operator is useful in the following scenarios:
152152
## Related content
153153

154154
[!INCLUDE[Related content](../includes/related-content.md)]
155+

articles/cosmos-db/mongodb/vcore/operators/miscellaneous-query/$rand.md

Lines changed: 121 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: $rand
3-
titleSuffix: Overview of the $rand operation in Azure Cosmos DB for MongoDB (vCore)
3+
titleSuffix: Overview of the $rand operator in Azure Cosmos DB for MongoDB (vCore)
44
description: The $rand operator generates a random float value between 0 and 1.
55
author: suvishodcitus
66
ms.author: suvishod
77
ms.service: azure-cosmos-db
88
ms.subservice: mongodb-vcore
99
ms.topic: language-reference
10-
ms.date: 02/12/2025
10+
ms.date: 09/04/2025
1111
---
1212

1313
# $rand
@@ -16,16 +16,130 @@ The `$rand` operator generates a random float value between 0 and 1. This is use
1616

1717
## Syntax
1818

19-
The syntax for the `$rand` operator is as follows:
20-
2119
```javascript
22-
{ $rand: {} }
20+
{
21+
$rand: {}
22+
}
2323
```
2424

2525
## Examples
2626

2727
Consider this sample document from the stores collection.
2828

29+
```json
30+
{
31+
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
32+
"name": "First Up Consultants | Beverage Shop - Satterfieldmouth",
33+
"location": {
34+
"lat": -89.2384,
35+
"lon": -46.4012
36+
},
37+
"staff": {
38+
"totalStaff": {
39+
"fullTime": 8,
40+
"partTime": 20
41+
}
42+
},
43+
"sales": {
44+
"totalSales": 75670,
45+
"salesByCategory": [
46+
{
47+
"categoryName": "Wine Accessories",
48+
"totalSales": 34440
49+
},
50+
{
51+
"categoryName": "Bitters",
52+
"totalSales": 39496
53+
},
54+
{
55+
"categoryName": "Rum",
56+
"totalSales": 1734
57+
}
58+
]
59+
},
60+
"promotionEvents": [
61+
{
62+
"eventName": "Unbeatable Bargain Bash",
63+
"promotionalDates": {
64+
"startDate": {
65+
"Year": 2024,
66+
"Month": 6,
67+
"Day": 23
68+
},
69+
"endDate": {
70+
"Year": 2024,
71+
"Month": 7,
72+
"Day": 2
73+
}
74+
},
75+
"discounts": [
76+
{
77+
"categoryName": "Whiskey",
78+
"discountPercentage": 7
79+
},
80+
{
81+
"categoryName": "Bitters",
82+
"discountPercentage": 15
83+
},
84+
{
85+
"categoryName": "Brandy",
86+
"discountPercentage": 8
87+
},
88+
{
89+
"categoryName": "Sports Drinks",
90+
"discountPercentage": 22
91+
},
92+
{
93+
"categoryName": "Vodka",
94+
"discountPercentage": 19
95+
}
96+
]
97+
},
98+
{
99+
"eventName": "Steal of a Deal Days",
100+
"promotionalDates": {
101+
"startDate": {
102+
"Year": 2024,
103+
"Month": 9,
104+
"Day": 21
105+
},
106+
"endDate": {
107+
"Year": 2024,
108+
"Month": 9,
109+
"Day": 29
110+
}
111+
},
112+
"discounts": [
113+
{
114+
"categoryName": "Organic Wine",
115+
"discountPercentage": 19
116+
},
117+
{
118+
"categoryName": "White Wine",
119+
"discountPercentage": 20
120+
},
121+
{
122+
"categoryName": "Sparkling Wine",
123+
"discountPercentage": 19
124+
},
125+
{
126+
"categoryName": "Whiskey",
127+
"discountPercentage": 17
128+
},
129+
{
130+
"categoryName": "Vodka",
131+
"discountPercentage": 23
132+
}
133+
]
134+
}
135+
]
136+
}
137+
```
138+
139+
### Example 1: Add a random value
140+
141+
This query adds a random value to each store document.
142+
29143
```javascript
30144
db.stores.aggregate([
31145
{
@@ -38,9 +152,8 @@ db.stores.aggregate([
38152
{ $limit: 2 }
39153
])
40154
```
41-
### Example 1: Add a random value
42155

43-
This query adds a random value to each store document. When executed, it might return something like:
156+
The first two results returned by this query are:
44157

45158
```json
46159
[
@@ -66,3 +179,4 @@ This query adds a random value to each store document. When executed, it might r
66179
## Related content
67180

68181
[!INCLUDE[Related content](../includes/related-content.md)]
182+

0 commit comments

Comments
 (0)