Skip to content

Commit ecd0e36

Browse files
Merge pull request #230486 from TimShererWithAquent/us2036619j
Freshness Pass User Story: 2036619 Query data by using Azure Cosmos DB's API for MongoDB
2 parents 381bcb3 + aff7615 commit ecd0e36

File tree

1 file changed

+135
-134
lines changed

1 file changed

+135
-134
lines changed

articles/cosmos-db/mongodb/tutorial-query.md

Lines changed: 135 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
2-
title: Query data with Azure Cosmos DB's API for MongoDB
3-
description: Learn how to query data from Azure Cosmos DB's API for MongoDB by using MongoDB shell commands
2+
title: Query data with Azure Cosmos DB for MongoDB
3+
description: Learn how to query data from Azure Cosmos DB for MongoDB by using MongoDB shell commands.
44
author: gahl-levy
55
ms.author: gahllevy
66
ms.service: cosmos-db
77
ms.subservice: mongodb
88
ms.custom: ignite-2022
99
ms.topic: tutorial
10-
ms.date: 12/03/2019
10+
ms.date: 03/14/2023
1111
ms.reviewer: mjbrown
1212
---
1313

14-
# Query data by using Azure Cosmos DB's API for MongoDB
14+
# Query data by using Azure Cosmos DB for MongoDB
1515
[!INCLUDE[MongoDB](../includes/appliesto-mongodb.md)]
1616

17-
The [Azure Cosmos DB's API for MongoDB](introduction.md) supports [MongoDB queries](https://docs.mongodb.com/manual/tutorial/query-documents/).
17+
The [Azure Cosmos DB for MongoDB](introduction.md) supports [MongoDB queries](https://docs.mongodb.com/manual/tutorial/query-documents/).
1818

19-
This article covers the following tasks:
19+
This article covers the following tasks:
2020

2121
> [!div class="checklist"]
2222
> * Querying data stored in your Azure Cosmos DB database using MongoDB shell
2323
24-
You can get started by using the examples in this document and watch the [Query Azure Cosmos DB with MongoDB shell](https://azure.microsoft.com/resources/videos/query-azure-cosmos-db-data-by-using-the-mongodb-shell/) video .
24+
You can get started by using the examples in this article.
2525

2626
## Sample document
2727

@@ -55,17 +55,18 @@ The queries in this article use the following sample document.
5555
"isRegistered": false
5656
}
5757
```
58-
## <a id="examplequery1"></a> Example query 1
5958

60-
Given the sample family document above, the following query returns the documents where the id field matches `WakefieldFamily`.
59+
## <a id="examplequery1"></a> Example query 1
6160

62-
**Query**
61+
Given the sample family document, the following query returns the documents where the `id` field matches `WakefieldFamily`.
62+
63+
Query:
6364

6465
```bash
6566
db.families.find({ id: "WakefieldFamily"})
6667
```
6768

68-
**Results**
69+
Results:
6970

7071
```json
7172
{
@@ -109,17 +110,17 @@ db.families.find({ id: "WakefieldFamily"})
109110
}
110111
```
111112

112-
## <a id="examplequery2"></a>Example query 2
113+
## <a id="examplequery2"></a>Example query 2
113114

114-
The next query returns all the children in the family.
115+
The next query returns all the children in the family.
115116

116-
**Query**
117+
Query:
117118

118-
```bash
119+
```bash
119120
db.families.find( { id: "WakefieldFamily" }, { children: true } )
120-
```
121+
```
121122
122-
**Results**
123+
Results:
123124
124125
```json
125126
{
@@ -145,187 +146,187 @@ db.families.find( { id: "WakefieldFamily" }, { children: true } )
145146
}
146147
```
147148
148-
## <a id="examplequery3"></a>Example query 3
149+
## <a id="examplequery3"></a>Example query 3
149150
150-
The next query returns all the families that are registered.
151+
The next query returns all the families that are registered.
151152
152-
**Query**
153+
Query:
153154
154155
```bash
155156
db.families.find( { "isRegistered" : true })
156-
```
157+
```
157158
158-
**Results**
159+
Results:
159160
160-
No document will be returned.
161+
No document is returned.
161162
162163
## <a id="examplequery4"></a>Example query 4
163164
164-
The next query returns all the families that are not registered.
165+
The next query returns all the families that aren't registered.
165166
166-
**Query**
167+
Query:
167168
168169
```bash
169170
db.families.find( { "isRegistered" : false })
170-
```
171+
```
171172
172-
**Results**
173+
Results:
173174
174175
```json
175176
{
176-
"_id": ObjectId("58f65e1198f3a12c7090e68c"),
177-
"id": "WakefieldFamily",
178-
"parents": [{
179-
"familyName": "Wakefield",
180-
"givenName": "Robin"
181-
}, {
182-
"familyName": "Miller",
183-
"givenName": "Ben"
184-
}],
185-
"children": [{
186-
"familyName": "Merriam",
187-
"givenName": "Jesse",
188-
"gender": "female",
189-
"grade": 1,
190-
"pets": [{
191-
"givenName": "Goofy"
192-
}, {
193-
"givenName": "Shadow"
194-
}]
195-
}, {
196-
"familyName": "Miller",
197-
"givenName": "Lisa",
198-
"gender": "female",
199-
"grade": 8
200-
}],
201-
"address": {
202-
"state": "NY",
203-
"county": "Manhattan",
204-
"city": "NY"
205-
},
206-
"creationDate": 1431620462,
207-
"isRegistered": false
177+
"_id": ObjectId("58f65e1198f3a12c7090e68c"),
178+
"id": "WakefieldFamily",
179+
"parents": [{
180+
"familyName": "Wakefield",
181+
"givenName": "Robin"
182+
}, {
183+
"familyName": "Miller",
184+
"givenName": "Ben"
185+
}],
186+
"children": [{
187+
"familyName": "Merriam",
188+
"givenName": "Jesse",
189+
"gender": "female",
190+
"grade": 1,
191+
"pets": [{
192+
"givenName": "Goofy"
193+
}, {
194+
"givenName": "Shadow"
195+
}]
196+
}, {
197+
"familyName": "Miller",
198+
"givenName": "Lisa",
199+
"gender": "female",
200+
"grade": 8
201+
}],
202+
"address": {
203+
"state": "NY",
204+
"county": "Manhattan",
205+
"city": "NY"
206+
},
207+
"creationDate": 1431620462,
208+
"isRegistered": false
208209
}
209210
```
210211
211212
## <a id="examplequery5"></a>Example query 5
212213
213-
The next query returns all the families that are not registered and state is NY.
214+
The next query returns all the families that aren't registered and state is NY.
214215
215-
**Query**
216+
Query:
216217
217218
```bash
218219
db.families.find( { "isRegistered" : false, "address.state" : "NY" })
219-
```
220+
```
220221
221-
**Results**
222+
Results:
222223
223224
```json
224225
{
225-
"_id": ObjectId("58f65e1198f3a12c7090e68c"),
226-
"id": "WakefieldFamily",
227-
"parents": [{
228-
"familyName": "Wakefield",
229-
"givenName": "Robin"
230-
}, {
231-
"familyName": "Miller",
232-
"givenName": "Ben"
233-
}],
234-
"children": [{
235-
"familyName": "Merriam",
236-
"givenName": "Jesse",
237-
"gender": "female",
238-
"grade": 1,
239-
"pets": [{
240-
"givenName": "Goofy"
241-
}, {
242-
"givenName": "Shadow"
243-
}]
244-
}, {
245-
"familyName": "Miller",
246-
"givenName": "Lisa",
247-
"gender": "female",
248-
"grade": 8
249-
}],
250-
"address": {
251-
"state": "NY",
252-
"county": "Manhattan",
253-
"city": "NY"
254-
},
255-
"creationDate": 1431620462,
256-
"isRegistered": false
226+
"_id": ObjectId("58f65e1198f3a12c7090e68c"),
227+
"id": "WakefieldFamily",
228+
"parents": [{
229+
"familyName": "Wakefield",
230+
"givenName": "Robin"
231+
}, {
232+
"familyName": "Miller",
233+
"givenName": "Ben"
234+
}],
235+
"children": [{
236+
"familyName": "Merriam",
237+
"givenName": "Jesse",
238+
"gender": "female",
239+
"grade": 1,
240+
"pets": [{
241+
"givenName": "Goofy"
242+
}, {
243+
"givenName": "Shadow"
244+
}]
245+
}, {
246+
"familyName": "Miller",
247+
"givenName": "Lisa",
248+
"gender": "female",
249+
"grade": 8
250+
}],
251+
"address": {
252+
"state": "NY",
253+
"county": "Manhattan",
254+
"city": "NY"
255+
},
256+
"creationDate": 1431620462,
257+
"isRegistered": false
257258
}
258259
```
259260
260261
## <a id="examplequery6"></a>Example query 6
261262
262263
The next query returns all the families where children grades are 8.
263264
264-
**Query**
265+
Query:
265266
266267
```bash
267268
db.families.find( { children : { $elemMatch: { grade : 8 }} } )
268269
```
269270
270-
**Results**
271+
Results:
271272
272273
```json
273274
{
274-
"_id": ObjectId("58f65e1198f3a12c7090e68c"),
275-
"id": "WakefieldFamily",
276-
"parents": [{
277-
"familyName": "Wakefield",
278-
"givenName": "Robin"
279-
}, {
280-
"familyName": "Miller",
281-
"givenName": "Ben"
282-
}],
283-
"children": [{
284-
"familyName": "Merriam",
285-
"givenName": "Jesse",
286-
"gender": "female",
287-
"grade": 1,
288-
"pets": [{
289-
"givenName": "Goofy"
290-
}, {
291-
"givenName": "Shadow"
292-
}]
293-
}, {
294-
"familyName": "Miller",
295-
"givenName": "Lisa",
296-
"gender": "female",
297-
"grade": 8
298-
}],
299-
"address": {
300-
"state": "NY",
301-
"county": "Manhattan",
302-
"city": "NY"
303-
},
304-
"creationDate": 1431620462,
305-
"isRegistered": false
275+
"_id": ObjectId("58f65e1198f3a12c7090e68c"),
276+
"id": "WakefieldFamily",
277+
"parents": [{
278+
"familyName": "Wakefield",
279+
"givenName": "Robin"
280+
}, {
281+
"familyName": "Miller",
282+
"givenName": "Ben"
283+
}],
284+
"children": [{
285+
"familyName": "Merriam",
286+
"givenName": "Jesse",
287+
"gender": "female",
288+
"grade": 1,
289+
"pets": [{
290+
"givenName": "Goofy"
291+
}, {
292+
"givenName": "Shadow"
293+
}]
294+
}, {
295+
"familyName": "Miller",
296+
"givenName": "Lisa",
297+
"gender": "female",
298+
"grade": 8
299+
}],
300+
"address": {
301+
"state": "NY",
302+
"county": "Manhattan",
303+
"city": "NY"
304+
},
305+
"creationDate": 1431620462,
306+
"isRegistered": false
306307
}
307308
```
308309
309310
## <a id="examplequery7"></a>Example query 7
310311
311312
The next query returns all the families where size of children array is 3.
312313
313-
**Query**
314+
Query:
314315
315316
```bash
316317
db.Family.find( {children: { $size:3} } )
317318
```
318319
319-
**Results**
320+
Results:
320321
321-
No results will be returned as there are no families with more than two children. Only when parameter is 2 this query will succeed and return the full document.
322+
No results are returned because there are no families with more than two children. Only when parameter value is `2` does this query succeed and return the full document.
322323
323324
## Next steps
324325
325-
In this tutorial, you've done the following:
326+
In this tutorial, you've done the following tasks:
326327
327328
> [!div class="checklist"]
328-
> * Learned how to query using Azure Cosmos DB’s API for MongoDB
329+
> * Learned how to query using Azure Cosmos DB for MongoDB
329330
330331
You can now proceed to the next tutorial to learn how to distribute your data globally.
331332

0 commit comments

Comments
 (0)