Skip to content

Commit e1e0c14

Browse files
authored
Merge pull request #96305 from SnehaGunda/MongoDb3.6
Mongo db3.6
2 parents f18d3c2 + 3ed332e commit e1e0c14

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

articles/cosmos-db/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,8 @@
672672
href: mongodb-readpreference.md
673673
- name: Time to live - MongoDB
674674
href: mongodb-time-to-live.md
675+
- name: Change streams
676+
href: mongodb-change-streams.md
675677
- name: Manage data indexing
676678
href: mongodb-indexing.md
677679
- name: Store and manage Spring Data
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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
5+
ms.service: cosmos-db
6+
ms.subservice: cosmosdb-mongo
7+
ms.topic: conceptual
8+
ms.date: 11/16/2019
9+
ms.author: srchi
10+
---
11+
12+
# Change streams in Azure Cosmos DB’s API for MongoDB
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.
15+
16+
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.
17+
18+
```javascript
19+
var cursor = db.coll.watch(
20+
[
21+
{ $match: { "operationType": { $in: ["insert", "update", "replace"] } } },
22+
{ $project: { "_id": 1, "fullDocument": 1, "ns": 1, "documentKey": 1 } }
23+
],
24+
{ fullDocument: "updateLookup" });
25+
26+
while (!cursor.isExhausted()) {
27+
if (cursor.hasNext()) {
28+
printjson(cursor.next());
29+
}
30+
}
31+
```
32+
33+
The following example shows how to get changes to the items in a single shard, such as shard "a" that has items with value "1".
34+
35+
```javascript
36+
var cursor = db.coll.watch(
37+
[
38+
{
39+
$match: {
40+
$and: [
41+
{ "fullDocument.a": 1 },
42+
{ "operationType": { $in: ["insert", "update", "replace"] } }
43+
]
44+
}
45+
},
46+
{ $project: { "_id": 1, "fullDocument": 1, "ns": 1, "documentKey": 1} }
47+
],
48+
{ fullDocument: "updateLookup" });
49+
50+
```
51+
52+
## Current limitations
53+
54+
The following limitations are applicable when using change streams:
55+
56+
* The `operationType` and `updateDescription` properties are not yet supported in the output document.
57+
* The `insert`, `update`, and `replace` operations types are currently supported. Delete operation or other events are not yet supported.
58+
59+
Due to these limitations, the $match stage, $project stage, and fullDocument options are required as shown in the previous examples.
60+
61+
## Error handling
62+
63+
The following error codes and messages are supported when using change streams:
64+
65+
* **HTTP error code 429** - When the change stream is throttled, it returns an empty page.
66+
67+
* **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.
68+
69+
## Next steps
70+
71+
* [Use time to live to expire data automatically in Azure Cosmos DB's API for MongoDB](mongodb-time-to-live.md)
72+
* [Indexing in Azure Cosmos DB's API for MongoDB](mongodb-indexing.md)

articles/cosmos-db/sql-api-get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ A database is the logical container of items partitioned across containers. Eith
254254
1. Select F5 to run your application.
255255

256256
> [!NOTE]
257-
> If you get a "503 service unavailable exception," it's possible the required [ports](performance-tips.md#networking) for direct mode are blocked by a firewall. To fix this issue, either open the required [ports](performance-tips.md#networking) or try to use gateway mode as shown below.
257+
> If you get a "503 service unavailable exception" error, it's possible that the required [ports](performance-tips.md#networking) for direct connectivity mode are blocked by a firewall. To fix this issue, either open the required ports or use the gateway mode connectivity as shown in the following code:
258258
```csharp
259259
// Create a new instance of the Cosmos Client in Gateway mode
260260
this.cosmosClient = new CosmosClient(EndpointUri, PrimaryKey, new CosmosClientOptions()

0 commit comments

Comments
 (0)