Skip to content

Commit 852e258

Browse files
committed
addressed the feedback comments and acrolynx score
1 parent 0fd4dea commit 852e258

File tree

3 files changed

+81
-79
lines changed

3 files changed

+81
-79
lines changed

articles/cosmos-db/mongodb/vcore/TOC.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
href: cross-region-replication.md
4545
- name: Indexing
4646
href: indexing-basics.md
47-
- name: Background indexing
48-
href: background-indexing.md
4947
- name: Reliability
5048
href: /azure/reliability/reliability-cosmos-mongodb?toc=/azure/cosmos-db/mongodb/vcore/toc.json
5149
- name: Compute and storage
@@ -80,14 +78,22 @@
8078
href: how-to-transactions.md
8179
- name: Connect using Spark connector from Azure Databricks
8280
href: connect-from-databricks.md
81+
- name: Work with indexes
82+
items:
83+
- name: Background indexing
84+
href: background-indexing.md
85+
- name: Indexing best practices
86+
href: how-to-create-indexes.md
87+
- name: Working with wildcard
88+
href: how-to-create-wildcard-indexes.md
89+
- name: Search and query text
90+
href: how-to-create-text-index.md
8391
- name: Scale cluster
8492
href: how-to-scale-cluster.md
8593
- name: Restore cluster
8694
href: how-to-restore-cluster.md
8795
- name: Manage replication
8896
href: how-to-cluster-replica.md
89-
- name: Search and query text
90-
href: how-to-create-text-index.md
9197
- name: Monitor diagnostics logs
9298
href: how-to-monitor-diagnostics-logs.md
9399
- name: Use Azure Private Link

articles/cosmos-db/mongodb/vcore/background-indexing.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Background Indexing
33
titleSuffix: Background Indexing on Azure Cosmos DB for MongoDB vCore
4-
description: background indexing to enable non-blocking operation during index creation
5-
author: avijitkgupta
6-
ms.author: avijitkgupta
4+
description: Background indexing to enable non-blocking operation during index creation
5+
author: avijitgupta
6+
ms.author: avijitgupta
77
ms.reviewer: gahllevy
88
ms.service: cosmos-db
99
ms.subservice: mongodb-vcore
@@ -13,12 +13,21 @@ ms.date: 06/27/2024
1313

1414
# Background indexing (Preview)
1515

16-
Background indexing is a technique that enables a database system to perform indexing operations on a collection without blocking other queries or updates. Azure CosmosDB for Mongo vcore accepts the indexing request and asynchronously performs it in background.
16+
[!INCLUDE[MongoDB vCore](~/reusable-content/ce-skilling/azure/includes/cosmos-db/includes/appliesto-mongodb-vcore.md)]
1717

18-
Azure Cosmos DB for Mongo vcore allows indexing in background with property `enableIndexBuildBackground` set to true”. All indexes would be created in background except the unique indexes, post enabling the property.
18+
Background indexing is a technique that enables a database system to perform indexing operations on a collection without blocking other queries or updates. Azure Cosmos DB for Mongo vcore accepts the background indexing request and asynchronously performs it in background.
19+
20+
Background indexing can be enabled using the property `enableIndexBuildBackground` set to `true`. All indexes would be created in background except the unique indexes, post enabling the property.
21+
22+
If working with smaller SKUs or workloads with higher I/O needs, it becomes necessary to predefine indexes on empty collections and avoid relying on background indexing.
1923

2024
> [!NOTE]
21-
> If anticipated data size is large enough for a collection, then it might be sensible to create index on an empty collection.
25+
> Enabling feature requires raising a support request.
26+
27+
> [!IMPORTANT]
28+
> Ensure creating unique indexes on an empty collection as those are created in foreground.
29+
>
30+
> It is vital to create indexes based on query predicates beforehand, while the collection is still empty. It prevents resource contention if pushed on read-write heavy large collection.
2231
2332
## Monitor index build
2433

@@ -31,7 +40,7 @@ db.currentOp("db_name":"<db_name>", "collection_name":"<collection_name>")
3140
- `db_name` is an optional parameter.
3241
- `collection_name` is optional parameter.
3342

34-
```json
43+
```javascript
3544
// Output for reviewing build status
3645
{
3746
inprog: [
@@ -56,7 +65,7 @@ inprog: [
5665
currentOpTime: ISODate("2024-06-24T10:08:20.000Z"),
5766
secs_running: Long("2"),
5867
command: {
59-
createIndexes: 'BRInventory-Multivendor', },
68+
createIndexes: 'BRInventory', },
6069
indexes: [
6170
{
6271
v:2,
@@ -80,16 +89,12 @@ inprog: [
8089
}
8190
```
8291

83-
We can observe the build status with values depicted in table.
92+
## Limitations
8493

85-
| Status_Value | Status | Description |
86-
|--------------|-------------|-------------|
87-
| 1 | Queued | Request is queued |
88-
| 2 | In progress | Request is picked |
89-
| 3 | Failed | Request is already failed, 3 more retries will be attempted |
90-
| 4 | Skippable | It should not be picked for processing. This should be deleted after 20 mins |
94+
- Unique indexes can't be created in the background, it's best to create them on an empty collection and then load the data.
95+
- Background indexing is performed sequentially within a single collection. However, background indexing can run concurrently across multiple collections.
9196

92-
## Limitations
97+
## Next Steps
9398

94-
- Unique indexes cannot be created as background index. We recommend user to create unique index on empty collection first and then load the data into it.
95-
- Background index are performed in sequence over a single collection. Though background indexes on multiple collections can run in parallel.
99+
> [!div class="nextstepaction"]
100+
> [Best Practices](how-to-create-indexes.md)

articles/cosmos-db/mongodb/vcore/indexing-basics.md

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
title: Indexes on Azure Cosmos DB for MongoDB vCore
33
titleSuffix: Azure Cosmos DB for MongoDB vCore
44
description: Basic know-how for efficient usage of indexes on Azure Cosmos DB for MongoDB vCore.
5-
author: avijitkgupta
6-
ms.author: avijitkgupta
5+
author: avijitgupta
6+
ms.author: avijitgupta
77
ms.reviewer: gahllevy
88
ms.service: cosmos-db
99
ms.subservice: mongodb-vcore
@@ -13,12 +13,34 @@ ms.date: 06/27/2024
1313

1414
# Manage indexing in Azure Cosmos DB for MongoDB vcore
1515

16-
[!INCLUDE[MongoDB vCore](../../includes/appliesto-mongodb-vcore.md)]
16+
[!INCLUDE[MongoDB vCore](~/reusable-content/ce-skilling/azure/includes/cosmos-db/includes/appliesto-mongodb-vcore.md)]
1717

1818
Indexes are structures that improve data retrieval speed by providing quick access to rows in a table. They work by creating an ordered set of pointers to data, often based on key columns. MongoDB vcore utilizes indexes in multiple contexts, including query push down, unique constraints and sharding.
1919

20+
> [!IMPORTANT]
21+
> The "_id" field is the **only** field indexed by default. It is recommended to add additional indexes based on query filters & predicates to optimize performance.
22+
2023
## Index types
2124

25+
For simplicity, let us consider an example of a blog application with the following setup:
26+
27+
- **Database name**: `cosmicworks`
28+
- **Collection name**: `products`
29+
30+
This example application stores articles as documents with the following structure. All the example quoted further utilizes the structure of this collection.
31+
32+
```json
33+
{
34+
"_id": ObjectId("617a34e7a867530bff1b2346"),
35+
"title": "Azure Cosmos DB - A Game Changer",
36+
"content": "Azure Cosmos DB is a globally distributed, multi-model database service.",
37+
"author": {lastName: "Doe", firstName: "John"},
38+
"category": "Technology",
39+
"launchDate": ISODate("2024-06-24T10:08:20.000Z"),
40+
"published": true
41+
}
42+
```
43+
2244
### Single field indexes
2345

2446
Single field indexes store information from a single field in a collection. The sort order of the single field index doesn't matter. _id field remains indexed by default.
@@ -29,13 +51,13 @@ MongoDB vcore supports creating index at following
2951
- Embedded document.
3052
- Fields within embedded document.
3153

32-
The following command creates a single field index on the field `name` and the following command creates it on an embedded field `firstName`.
54+
The following command creates a single field index on the field `author` and the following command creates it on an embedded field `firstName`.
3355

3456
```javascript
35-
db.coll.createIndex({"name": 1})
57+
db.coll.createIndex({"author": 1})
3658

3759
// indexing embedded property
38-
db.coll.createIndex({"name.firstName": -1})
60+
db.coll.createIndex({"author.firstName": -1})
3961
```
4062

4163
One query can use multiple single field indexes where available.
@@ -47,16 +69,16 @@ One query can use multiple single field indexes where available.
4769

4870
Compound indexes are required if your query needs the ability to **query or sort** data from two or more fields in each document in a collection.
4971

50-
The following command creates a compound index on the fields `name` and `age` in opposite sort order.
72+
The following command creates a compound index on the fields `author` and `launchDate` in opposite sort order.
5173

5274
```javascript
53-
db.coll.createIndex({"name":1, "age":-1})
75+
db.coll.createIndex({"author":1, "launchDate":-1})
5476
```
5577

5678
`Order` of columns affect the selectivity or utilization of index. The `find` query wouldn't utilize the index created.
5779

5880
```javascript
59-
db.coll.find({age: {$gt: 25}})
81+
db.coll.find({"launchDate": {$gt: ISODate("2024-06-01T00:00:00.000Z")}})
6082
```
6183

6284
Compounded indexes on nested fields aren't supported by default due to limitations with arrays. If your nested field doesn't contain an array, the index works as intended. If your nested field contains an array (anywhere on the path), that value is ignored in the index.
@@ -65,33 +87,23 @@ As an example, a compound index containing `people.dylan.age` works in this case
6587

6688
```json
6789
{
68-
"people": {
69-
"dylan": {
70-
"name": "Dylan",
71-
"age": "25"
72-
},
73-
"reed": {
74-
"name": "Reed",
75-
"age": "30"
76-
}
77-
}
90+
"_id": ObjectId("617a34e7a867530bff1b2346"),
91+
"title": "The Culmination",
92+
"author": {lastName: "Lindsay", firstName: "Joseph"},
93+
"launchDate": ISODate("2024-06-24T10:08:20.000Z"),
94+
"published": true
7895
}
7996
```
8097

8198
This same compound index doesn't work in this case since there's an array in the path:
8299

83100
```json
84101
{
85-
"people": [
86-
{
87-
"name": "Dylan",
88-
"age": "25"
89-
},
90-
{
91-
"name": "Reed",
92-
"age": "30"
93-
}
94-
]
102+
"_id": ObjectId("617a34e7a867530bff1b2346"),
103+
"title": "Beautiful Creatures",
104+
"author": [ {lastName: "Garcia", firstName: "Kami"}, {lastName: "Stohl", firstName: "Margaret"} ],
105+
"launchDate": ISODate("2024-06-24T10:08:20.000Z"),
106+
"published": true
95107
}
96108
```
97109

@@ -106,8 +118,8 @@ Indexes that have an associated query filter that describes when to generate a t
106118

107119
```javascript
108120
db.coll.createIndex (
109-
{ name: 1, age: 1 },
110-
{ partialFilterExpression: { age: { $gt: 5 } } }
121+
{ "author": 1, "launchDate": 1 },
122+
{ partialFilterExpression: { "launchDate": { $gt: ISODate("2024-06-24T10:08:20.000Z") } } }
111123
)
112124
```
113125

@@ -119,24 +131,6 @@ db.coll.createIndex (
119131

120132
Text indexes are special data structures that optimize text-based queries, making them faster and more efficient.
121133

122-
For simplicity, let us consider an example of a blog application with the following setup:
123-
124-
- **Database name**: `cosmicworks`
125-
- **Collection name**: `products`
126-
127-
This example application stores articles as documents with the following structure.
128-
129-
```json
130-
{
131-
"_id": ObjectId("617a34e7a867530bff1b2346"),
132-
"title": "Azure Cosmos DB - A Game Changer",
133-
"content": "Azure Cosmos DB is a globally distributed, multi-model database service.",
134-
"author": "John Doe",
135-
"category": "Technology",
136-
"published": true
137-
}
138-
```
139-
140134
Use the `createIndex` method with the `text` option to create a text index on the `title` field.
141135

142136
```javascript
@@ -198,7 +192,7 @@ db.products.find(
198192
Index on single field, indexes all paths beneath the `field` , excluding other fields that are on the same level. For example, for the following sample document
199193

200194
```javascript
201-
"children": [
195+
"children":
202196
{
203197
"familyName": "Merriam",
204198
"pets": { "details": {“name”: "Goofy", ”age”: 3} }
@@ -315,11 +309,8 @@ db.collection.createIndex({a: "2d", b: 1})
315309
// MongoServerError: $geoNear requires a 'key' option as a String
316310
```
317311

318-
## Related content
319-
320-
Check out [text indexing](how-to-create-text-index.md), which allows for efficient searching and querying of text-based data.
321-
322-
## Next step
312+
## Next steps
323313

324-
> [!div class="nextstepaction"]
325-
> [Build a Node.js web application](tutorial-nodejs-web-app.md)
314+
- Check more on how to work with [text indexing](how-to-create-text-index.md).
315+
- Check more on how to work with [wildcard indexing](how-to-create-wildcard-indexes.md).
316+
- Review [Best Practices](how-to-create-indexes.md) for best possible outcome on Azure CosmosDB for MongoDB vcore.

0 commit comments

Comments
 (0)