You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/mongodb-change-streams.md
+58-29Lines changed: 58 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,45 @@
1
1
---
2
-
title: Change streams in Azure Cosmos DB’s API for MongoDB
3
-
description: Learn how to use change streams n Azure Cosmos DB’s API for MongoDB to get the changes made to your data.
4
-
author: srchi
2
+
title: Change streams in Azure Cosmos DB's API for MongoDB
3
+
description: Learn how to use change streams in Azure Cosmos DB's API for MongoDB to get the changes made to your data.
4
+
author: timsander1
5
5
ms.service: cosmos-db
6
6
ms.subservice: cosmosdb-mongo
7
7
ms.topic: conceptual
8
-
ms.date: 11/16/2019
9
-
ms.author: srchi
8
+
ms.date: 03/30/2020
9
+
ms.author: tisande
10
10
---
11
11
12
-
# Change streams in Azure Cosmos DB’s API for MongoDB
12
+
# Change streams in Azure Cosmos DB's API for MongoDB
13
13
14
-
[Change feed](change-feed.md) support in Azure Cosmos DB’s API for MongoDB is available by using the change streams API. By using the change streams API, your applications can get the changes made to the collection or to the items in a single shard. Later you can take further actions based on the results. Changes to the items in the collection are captured in the order of their modification time and the sort order is guaranteed per shard key.
14
+
[Change feed](change-feed.md) support in Azure Cosmos DB's API for MongoDB is available by using the change streams API. By using the change streams API, your applications can get the changes made to the collection or to the items in a single shard. Later you can take further actions based on the results. Changes to the items in the collection are captured in the order of their modification time and the sort order is guaranteed per shard key.
15
15
16
16
> [!NOTE]
17
-
> To use change streams, create the account with version 3.6 of Azure Cosmos DB's API for MongoDB, or a later version. If you run the change stream examples against an earlier version, you might see the `Unrecognized pipeline stage name: $changeStream` error.
17
+
> To use change streams, create the account with version 3.6 of Azure Cosmos DB's API for MongoDB, or a later version. If you run the change stream examples against an earlier version, you might see the `Unrecognized pipeline stage name: $changeStream` error.
18
18
19
-
The following example shows how to get change streams on all the items in the collection. This example creates a cursor to watch items when they are inserted, updated, or replaced. The $match stage, $project stage, and fullDocument option are required to get the change streams. Watching for delete operations using change streams is currently not supported. As a workaround, you can add a soft marker on the items that are being deleted. For example, you can add an attribute in the item called "deleted" and set it to "true" and set a TTL on the item, so that you can automatically delete it as well as track it.
19
+
## Current limitations
20
+
21
+
The following limitations are applicable when using change streams:
22
+
23
+
* The `operationType` and `updateDescription` properties are not yet supported in the output document.
24
+
* The `insert`, `update`, and `replace` operations types are currently supported. Delete operation or other events are not yet supported.
25
+
26
+
Due to these limitations, the $match stage, $project stage, and fullDocument options are required as shown in the previous examples.
27
+
28
+
Unlike the change feed in Azure Cosmos DB's SQL API, there is not a separate [Change Feed Processor Library](change-feed-processor.md) to consume change streams or a need for a leases container. There is not currently support for [Azure Functions triggers](change-feed-functions.md) to process change streams.
29
+
30
+
## Error handling
31
+
32
+
The following error codes and messages are supported when using change streams:
33
+
34
+
***HTTP error code 16500** - When the change stream is throttled, it returns an empty page.
35
+
36
+
***NamespaceNotFound (OperationType Invalidate)** - If you run change stream on the collection that does not exist or if the collection is dropped, then a `NamespaceNotFound` error is returned. Because the `operationType` property can't be returned in the output document, instead of the `operationType Invalidate` error, the `NamespaceNotFound` error is returned.
37
+
38
+
## Examples
39
+
40
+
The following example shows how to get change streams on all the items in the collection. This example creates a cursor to watch items when they are inserted, updated, or replaced. The `$match` stage, `$project` stage, and `fullDocument` option are required to get the change streams. Watching for delete operations using change streams is currently not supported. As a workaround, you can add a soft marker on the items that are being deleted. For example, you can add an attribute in the item called "deleted." When you'd like to delete the item, you can set "deleted" to `true` and set a TTL on the item. Since updating "deleted" to `true` is an update, this change will be visible in the change stream.
41
+
42
+
### JavaScript:
20
43
21
44
```javascript
22
45
var cursor =db.coll.watch(
@@ -33,13 +56,36 @@ while (!cursor.isExhausted()) {
33
56
}
34
57
```
35
58
36
-
The following example shows how to get changes to the items in a single shard. This example gets the changes of items that have shard key equal to "a" and the shard key value equal to "1".
The following example shows how to get changes to the items within a single shard. This example gets the changes of items that have shard key equal to "a" and the shard key value equal to "1". It is possible to have different clients reading changes from different shards in parallel.
The following limitations are applicable when using change streams:
58
-
59
-
* The `operationType` and `updateDescription` properties are not yet supported in the output document.
60
-
* The `insert`, `update`, and `replace` operations types are currently supported. Delete operation or other events are not yet supported.
61
-
62
-
Due to these limitations, the $match stage, $project stage, and fullDocument options are required as shown in the previous examples.
63
-
64
-
## Error handling
65
-
66
-
The following error codes and messages are supported when using change streams:
67
-
68
-
***HTTP error code 429** - When the change stream is throttled, it returns an empty page.
69
-
70
-
***NamespaceNotFound (OperationType Invalidate)** - If you run change stream on the collection that does not exist or if the collection is dropped, then a `NamespaceNotFound` error is returned. Because the `operationType` property can't be returned in the output document, instead of the `operationType Invalidate` error, the `NamespaceNotFound` error is returned.
71
-
72
101
## Next steps
73
102
74
103
*[Use time to live to expire data automatically in Azure Cosmos DB's API for MongoDB](mongodb-time-to-live.md)
0 commit comments