Skip to content

Commit 546a2e0

Browse files
authored
Merge pull request #192600 from nayakshweta/shwetn_marchreleases
Updates recent improvements in unique indexes, TTL indexes and $expr.
2 parents 198eedc + 4cc34ae commit 546a2e0

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

articles/cosmos-db/mongodb/feature-support-36.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn about Azure Cosmos DB's API for MongoDB (3.6 version) support
44
ms.service: cosmos-db
55
ms.subservice: cosmosdb-mongo
66
ms.topic: overview
7-
ms.date: 03/02/2021
7+
ms.date: 04/04/2022
88
author: gahl-levy
99
ms.author: gahllevy
1010
---
@@ -377,7 +377,7 @@ Azure Cosmos DB's API for MongoDB supports the following database commands:
377377
|---------|---------|
378378
| TTL | Yes |
379379
| Unique | Yes |
380-
| Partial | No |
380+
| Partial | Only supported with unique indexes |
381381
| Case Insensitive | No |
382382
| Sparse | No |
383383
| Background | Yes |
@@ -404,7 +404,7 @@ Azure Cosmos DB's API for MongoDB supports the following database commands:
404404

405405
| Command | Supported |
406406
|---------|---------|
407-
| $expr | No |
407+
| $expr | Yes |
408408
| $jsonSchema | No |
409409
| $mod | Yes |
410410
| $regex | Yes |

articles/cosmos-db/mongodb/feature-support-40.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn about Azure Cosmos DB's API for MongoDB 4.0 server version su
44
ms.service: cosmos-db
55
ms.subservice: cosmosdb-mongo
66
ms.topic: overview
7-
ms.date: 08/26/2021
7+
ms.date: 04/05/2022
88
author: gahl-levy
99
ms.author: gahllevy
1010
---
@@ -399,7 +399,7 @@ In an [upgrade scenario](upgrade-mongodb-version.md), documents written prior to
399399
|---------|---------|
400400
| TTL | Yes |
401401
| Unique | Yes |
402-
| Partial | No |
402+
| Partial | Only supported with unique indexes |
403403
| Case Insensitive | No |
404404
| Sparse | No |
405405
| Background | Yes |
@@ -426,7 +426,7 @@ In an [upgrade scenario](upgrade-mongodb-version.md), documents written prior to
426426

427427
| Command | Supported |
428428
|---------|---------|
429-
| $expr | No |
429+
| $expr | Yes |
430430
| $jsonSchema | No |
431431
| $mod | Yes |
432432
| $regex | Yes |
@@ -557,7 +557,7 @@ Azure Cosmos DB does not yet support server-side sessions commands.
557557

558558
## Time-to-live (TTL)
559559

560-
Azure Cosmos DB supports a time-to-live (TTL) based on the timestamp of the document. TTL can be enabled for collections by going to the [Azure portal](https://portal.azure.com).
560+
Azure Cosmos DB supports a time-to-live (TTL) based on the timestamp of the document. TTL can be enabled for collections from the [Azure portal](https://portal.azure.com).
561561

562562
## Transactions
563563

@@ -577,5 +577,5 @@ Some applications rely on a [Write Concern](https://docs.mongodb.com/manual/refe
577577
- Learn how to [use Robo 3T](connect-using-robomongo.md) with Azure Cosmos DB's API for MongoDB.
578578
- Explore MongoDB [samples](nodejs-console-app.md) with Azure Cosmos DB's API for MongoDB.
579579
- Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning.
580-
- If all you know is the number of vcores and servers in your existing database cluster, read about [estimating request units using vCores or vCPUs](../convert-vcore-to-request-unit.md)
580+
- If all you know is the number of vCores and servers in your existing database cluster, read about [estimating request units using vCores or vCPUs](../convert-vcore-to-request-unit.md)
581581
- If you know typical request rates for your current database workload, read about [estimating request units using Azure Cosmos DB capacity planner](estimate-ru-capacity-planner.md)

articles/cosmos-db/mongodb/feature-support-42.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn about Azure Cosmos DB API for MongoDB 4.2 server version supp
44
ms.service: cosmos-db
55
ms.subservice: cosmosdb-mongo
66
ms.topic: overview
7-
ms.date: 02/23/2022
7+
ms.date: 04/05/2022
88
author: gahl-levy
99
ms.author: gahllevy
1010
---
@@ -431,7 +431,7 @@ In an [upgrade scenario](upgrade-mongodb-version.md), documents written prior to
431431
|---------|---------|
432432
| TTL | Yes |
433433
| Unique | Yes |
434-
| Partial | No |
434+
| Partial | Only supported with unique indexes |
435435
| Case Insensitive | No |
436436
| Sparse | No |
437437
| Background | Yes |
@@ -458,7 +458,7 @@ In an [upgrade scenario](upgrade-mongodb-version.md), documents written prior to
458458

459459
| Command | Supported |
460460
|---------|---------|
461-
| $expr | No |
461+
| $expr | Yes |
462462
| $jsonSchema | No |
463463
| $mod | Yes |
464464
| $regex | Yes |
@@ -595,7 +595,7 @@ Azure Cosmos DB does not yet support server-side sessions commands.
595595

596596
## Time-to-live (TTL)
597597

598-
Azure Cosmos DB supports a time-to-live (TTL) based on the timestamp of the document. TTL can be enabled for collections by going to the [Azure portal](https://portal.azure.com).
598+
Azure Cosmos DB supports a time-to-live (TTL) based on the timestamp of the document. TTL can be enabled for collections from the [Azure portal](https://portal.azure.com).
599599

600600
## Transactions
601601

@@ -615,5 +615,5 @@ Some applications rely on a [Write Concern](https://docs.mongodb.com/manual/refe
615615
- Learn how to [use Robo 3T](connect-using-robomongo.md) with Azure Cosmos DB API for MongoDB.
616616
- Explore MongoDB [samples](nodejs-console-app.md) with Azure Cosmos DB API for MongoDB.
617617
- Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning.
618-
- If all you know is the number of vcores and servers in your existing database cluster, read about [estimating request units using vCores or vCPUs](../convert-vcore-to-request-unit.md).
618+
- If all you know is the number of vCores and servers in your existing database cluster, read about [estimating request units using vCores or vCPUs](../convert-vcore-to-request-unit.md).
619619
- If you know typical request rates for your current database workload, read about [estimating request units using Azure Cosmos DB capacity planner](estimate-ru-capacity-planner.md).

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.service: cosmos-db
55
ms.subservice: cosmosdb-mongo
66
ms.devlang: javascript
77
ms.topic: how-to
8-
ms.date: 10/13/2021
8+
ms.date: 4/5/2022
99
author: gahl-levy
1010
ms.author: gahllevy
1111
ms.custom: devx-track-js, cosmos-db-video
@@ -203,9 +203,6 @@ The following operations are common for accounts serving wire protocol version 4
203203

204204
[Unique indexes](../unique-keys.md) are useful for enforcing that two or more documents do not contain the same value for indexed fields.
205205

206-
> [!IMPORTANT]
207-
> Unique indexes can be created only when the collection is empty (contains no documents).
208-
209206
The following command creates a unique index on the field `student_id`:
210207

211208
```shell
@@ -244,6 +241,43 @@ In the preceding example, omitting the ```"university":1``` clause returns an er
244241
245242
`cannot create unique index over {student_id : 1.0} with shard key pattern { university : 1.0 }`
246243
244+
#### Limitations
245+
246+
On accounts that have continuous backup or synapse link enabled, unique indexes will need to be created while the collection is empty.
247+
248+
#### Unique partial indexes
249+
250+
Unique partial indexes can be created by specifying a partialFilterExpression along with the 'unique' constraint in the index. This results in the unique constraint being applied only to the documents that meet the specified filter expression.
251+
252+
The unique constraint will not be effective for documents that do not meet the specified criteria. As a result, other documents will not be prevented from being inserted into the collection.
253+
254+
This feature is supported with the Cosmos DB API for MongoDB versions 3.6 and above.
255+
256+
To create a unique partial index from Mongo Shell, use the command `db.collection.createIndex()` with the 'partialFilterExpression' option and 'unique' constraint.
257+
The partialFilterExpression option accepts a json document that specifies the filter condition using:
258+
259+
* equality expressions (i.e. field: value or using the $eq operator),
260+
*'$exists: true' expression,
261+
* $gt, $gte, $lt, $lte expressions,
262+
* $type expressions,
263+
* $and operator at the top-level only
264+
265+
The following command creates an index on collection `books` that specifies a unique constraint on the `title` field and a partial filter expression `rating: { $gte: 3 }`:
266+
267+
```shell
268+
db.books.createIndex(
269+
{ title: 1 },
270+
{ unique: true, partialFilterExpression: { rating: { $gte: 3 } } }
271+
)
272+
```
273+
274+
To delete a partial unique index using om Mongo Shell, use the command `getIndexes()` to list the indexes in the collection.
275+
Then drop the index with the following command:
276+
277+
```shell
278+
db.books.dropIndex("indexName")
279+
```
280+
247281
### TTL indexes
248282
249283
To enable document expiration in a particular collection, you need to create a [time-to-live (TTL) index](../time-to-live.md). A TTL index is an index on the `_ts` field with an `expireAfterSeconds` value.

0 commit comments

Comments
 (0)