Skip to content

Commit 203c442

Browse files
committed
Update indexing.md
1 parent 4e47d62 commit 203c442

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

articles/cosmos-db/mongodb/indexing.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,19 @@ In the API for MongoDB, compound indexes are **required** if your query needs th
5252

5353
A compound index or single field indexes for each field in the compound index will result in the same performance for filtering in queries.
5454

55-
Compounded indexes on nested fields are not supported by default due to limiations with arrays. If your nested field does not contain an array, the index will work as intended. If your nested field contains an array, that value will be ignored in the index. This feature can be enabled for your database account by [enabling the 'EnableUniqueCompoundNestedDocs' capability](how-to-configure-capabilities.md).
55+
Compounded indexes on nested fields are not supported by default due to limiations with arrays. If your nested field does not contain an array, the index will work as intended. If your nested field contains an array (anywhere on the path), that value will be ignored in the index.
56+
57+
For example a compound index containing people.tom.age will work in this case since there's no array on the path:
58+
```javascript
59+
{ "people": { "tom": { "age": "25" }, "mark": { "age": "30" } } }
60+
```
61+
but won't won't work in this case since there's an array in the path:
62+
```javascript
63+
{ "people": { "tom": [ { "age": "25" } ], "mark": [ { "age": "30" } ] } }
64+
```
65+
66+
This feature can be enabled for your database account by [enabling the 'EnableUniqueCompoundNestedDocs' capability](how-to-configure-capabilities.md).
67+
5668

5769
> [!NOTE]
5870
> You can't create compound indexes on arrays.
@@ -246,7 +258,19 @@ In the preceding example, omitting the ```"university":1``` clause returns an er
246258
247259
Unique indexes need to be created while the collection is empty.
248260
249-
Unique indexes on nested fields are not supported by default due to limiations with arrays. If your nested field does not contain an array, the index will work as intended. If your nested field contains an array, that value will be ignored in the unique index and uniqueness wil not be preserved for that value. This feature can be enabled for your database account by [enabling the 'EnableUniqueCompoundNestedDocs' capability](how-to-configure-capabilities.md).
261+
Unique indexes on nested fields are not supported by default due to limiations with arrays. If your nested field does not contain an array, the index will work as intended. If your nested field contains an array (anywhere on the path), that value will be ignored in the unique index and uniqueness wil not be preserved for that value.
262+
263+
For example a unique index on people.tom.age will work in this case since there's no array on the path:
264+
```javascript
265+
{ "people": { "tom": { "age": "25" }, "mark": { "age": "30" } } }
266+
```
267+
but won't won't work in this case since there's an array in the path:
268+
```javascript
269+
{ "people": { "tom": [ { "age": "25" } ], "mark": [ { "age": "30" } ] } }
270+
```
271+
272+
This feature can be enabled for your database account by [enabling the 'EnableUniqueCompoundNestedDocs' capability](how-to-configure-capabilities.md).
273+
250274
251275
### TTL indexes
252276

0 commit comments

Comments
 (0)