@@ -21,20 +21,61 @@ Change Streams
21
21
Change streams allow applications to access real-time data changes
22
22
without the complexity and risk of tailing the :term:`oplog`.
23
23
Applications can use change streams to subscribe to all data changes on
24
- a collection and immediately react to them.
24
+ a single collection, a database, or an entire deployment, and
25
+ immediately react to them. Because change streams use the aggregation
26
+ framework, applications can also filter for specific changes or
27
+ transform the notifications at will.
28
+
29
+ Change stream is available for :doc:`replica sets <replication>` and
30
+ :doc:`sharded clusters </sharding>` that use :ref:`WiredTiger
31
+ <storage-wiredtiger>` storage engine and replica set protocol version 1
32
+ (:rsconf:`pv1 <protocolVersion>`). Change streams can also be used on
33
+ deployments which employ MongoDB's
34
+ :ref:`encryption-at-rest<encrypted-storage-engine>` feature.
35
+
36
+ Watch Collection/Database/Deployment
37
+ ------------------------------------
38
+
39
+ You can open change streams against:
40
+
41
+ - A single collection (except ``system`` collections, or any
42
+ collections in the ``admin``, ``local``, and ``config`` databases)
43
+
44
+ See the :binary:`~bin.mongo` shell method
45
+ :method:`db.collection.watch()`.
46
+
47
+ For the corresponding MongoDB driver method, refer to your driver
48
+ documentation.
49
+
50
+ - .. versionadded:: 4.0
51
+
52
+ A database (excluding the ``admin``, ``local``, ``config``
53
+ databases). The change stream watches for changes to all
54
+ non-``system`` collections in the database.
55
+
56
+ :binary:`~bin.mongo` shell provides the method
57
+ :method:`db.watch()`. For the corresponding MongoDB driver method,
58
+ refer to your driver documentation.
59
+
60
+ - .. versionadded:: 4.0
61
+
62
+ An entire deployment, either a replica set or a sharded cluster.
63
+ The change stream watches for changes to all non-``system``
64
+ collections across all databases, except for the ``admin``.
65
+ ``local``, and ``config`` databases.
66
+
67
+ :binary:`~bin.mongo` shell provides the
68
+ method :method:`Mongo.watch()`. For the corresponding MongoDB
69
+ driver method, refer to your driver documentation.
25
70
26
71
Open A Change Stream
27
72
--------------------
28
73
29
- You can only open a change stream against :doc:`replica sets
30
- <replication>` or :doc:`sharded clusters </sharding>`. For a sharded
31
- cluster, you must issue the open change stream operation against the
32
- :binary:`~bin.mongos`.
74
+ For a replica set, you can open change stream for any of the
75
+ data-bearing members.
33
76
34
- The replica set or the sharded cluster must use replica set protocol
35
- version 1 (:rsconf:`pv1 <protocolVersion>`) and :ref:`WiredTiger
36
- <storage-wiredtiger>` storage engine (can be :ref:`encrypted
37
- <encrypted-storage-engine>`).
77
+ For a sharded cluster, you must issue the open change stream operation
78
+ against the :binary:`~bin.mongos`.
38
79
39
80
.. tabs-drivers::
40
81
@@ -89,9 +130,9 @@ version 1 (:rsconf:`pv1 <protocolVersion>`) and :ref:`WiredTiger
89
130
<https://docs.mongodb.com/ruby-driver/master/tutorials/ruby-driver-create-client/>`__
90
131
that contains an ``inventory`` collection.
91
132
92
- The following example opens a change stream against a replica set. The change stream is bound to a collection and
93
- change stream documents are iterated with a cursor. This cursor remains open until it is explicitly closed,
94
- as long as a connection to the MongoDB deployment remains open *and* the collection exists .
133
+ The following example opens a change stream for a collection and iterates over the cursor to retrieve the
134
+ change stream documents . As long as the connection to the MongoDB deployment remains open *and* the collection exists,
135
+ this cursor remains open until it is explicitly closed .
95
136
96
137
.. tabs-drivers::
97
138
@@ -611,8 +652,33 @@ Access Control
611
652
--------------
612
653
613
654
For deployments enforcing :ref:`authentication` and :ref:`authorization
614
- <authorization>`, applications can only open change streams against
615
- collections they have read access to.
655
+ <authorization>`:
656
+
657
+ - To open a change stream against specific collection, applications
658
+ must have privileges that grant :authaction:`changeStream` and
659
+ :authaction:`find` actions on the corresponding collection.
660
+
661
+ .. code-block:: javascript
662
+
663
+ { resource: { db: <dbname>, collection: <collection> }, actions: [ "find", "changeStream" ] }
664
+
665
+ - To open a change stream on a single databases, applications must have
666
+ privileges that grant :authaction:`changeStream` and
667
+ :authaction:`find` actions on all non-``system`` collections in a
668
+ database.
669
+
670
+ .. code-block:: javascript
671
+
672
+ { resource: { db: <dbname>, collection: "" }, actions: [ "find", "changeStream" ] }
673
+
674
+ - To open a change stream on an entire deployment, applications must
675
+ have privileges that grant :authaction:`changeStream` and
676
+ :authaction:`find` actions on all non-``system`` collections for all
677
+ databases in the deployment.
678
+
679
+ .. code-block:: javascript
680
+
681
+ { resource: { db: "", collection: "" }, actions: [ "find", "changeStream" ] }
616
682
617
683
Event Notification
618
684
------------------
0 commit comments