Skip to content

Docsp 1505 new #3200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ examples:
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-ruby-driver/master/spec/mongo/change_stream_examples_spec.rb -o ${DRIVERS_PATH}/change_stream_examples_spec.rb
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-scala-driver/master/driver/src/it/scala/org/mongodb/scala/DocumentationExampleSpec.scala -o ${DRIVERS_PATH}/DocumentationExampleSpec.scala
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-csharp-driver/master/tests/MongoDB.Driver.Examples/DocumentationExamples.cs -o ${DRIVERS_PATH}/DocumentationExamples.cs
curl -SfL https://raw.githubusercontent.com/mongodb/node-mongodb-native/3.0.0/test/functional/operation_changestream_example_tests.js -o ${DRIVERS_PATH}/ChangeStreamNodeExamples.js
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-csharp-driver/master/tests/MongoDB.Driver.Examples/ChangeStreamExamples.cs -o ${DRIVERS_PATH}/ChangeStreamExamples.cs
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-c-driver/master/tests/test-mongoc-sample-commands.c -o ${DRIVERS_PATH}/test-mongoc-sample-commands.c
curl -Sfl https://raw.githubusercontent.com/mongodb/mongo-java-driver-reactivestreams/master/examples/documentation/src/DocumentationSamples.java -o ${DRIVERS_PATH}/AsyncDocumentationSamples.java
Expand Down
82 changes: 68 additions & 14 deletions source/tutorial/change-streams-example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Change Stream Examples
Change streams are available for replica sets or sharded clusters with replica set
shards. You cannot open a change stream against a standalone :binary:`~bin.mongod`.
For a sharded cluster, you must issue the open change stream operation against
the :binary:`~bin.mongos`.
the :binary:`~bin.mongos`.

The replica set or the sharded cluster must use:

Expand All @@ -28,32 +28,38 @@ Change Stream Examples
:depth: 1
:class: singlecol

.. tabs-drivers::

.. tabs-drivers::

tabs:
- id: python
content: |

The examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://api.mongodb.com/python/current/tutorial.html?_ga=2.166792574.1325858930.1510605946-1663796716.1426889906#making-a-connection-with-mongoclient/>`__
The Python examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://api.mongodb.com/python/current/tutorial.html?_ga=2.166792574.1325858930.1510605946-1663796716.1426889906#making-a-connection-with-mongoclient/>`_
that contains an ``inventory`` collection.

- id: java-sync
content: |
The examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://mongodb.github.io/mongo-java-driver/3.6/driver/tutorials/databases-collections/>`__
The Java examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://mongodb.github.io/mongo-java-driver/3.6/driver/tutorials/databases-collections/>`_
that contains an ``inventory`` collection.

- id: csharp
content: |
The examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://mongodb.github.io/mongo-csharp-driver/2.4/getting_started/quick_tour/#make-a-connection/>`__
that contains an ``inventory`` collection.
The C# examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://mongodb.github.io/mongo-csharp-driver/2.4/getting_started/quick_tour/#make-a-connection/>`_
that contains an ``inventory`` collection.

- id: c
content: |
The examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://mongoc.org/libmongoc/current/tutorial.html#making-a-connection/>`__
The C examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<http://mongoc.org/libmongoc/current/tutorial.html#making-a-connection/>`_
that contains an ``inventory`` collection.

- id: nodejs
content: |
The Node.js examples below assume that you have `connected to a MongoDB replica set and have accessed a database
<https://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html#connect>`_
that contains an ``inventory`` collection.

- id: ruby
Expand Down Expand Up @@ -112,6 +118,17 @@ as long as a connection to the MongoDB deployment remains open *and* the collect
:start-after: Start Changestream Example 1
:end-before: End Changestream Example 1


- id: nodejs
content: |
.. class:: copyable-code

.. literalinclude:: /driver-examples/ChangeStreamNodeExamples.js
:language: nodejs
:dedent: 0
:start-after: Start Changestream Example 1
:end-before: End Changestream Example 1

- id: ruby
content: |
.. class:: copyable-code
Expand Down Expand Up @@ -165,6 +182,15 @@ Lookup Full Document for Update Operations
document, pass ``"FullDocument = ChangeStreamFullDocumentOption.UpdateLookup"`` to the
:method:`collection.Watch()` method.


- id: nodejs
content: |
By default, change streams only return the delta of fields during the update operation.
To return the most current majority-committed version of the updated
document, pass ``{ fullDocument: 'updateLookup' }`` to the
:method:`collection.watch()` method.


- id: ruby
content: |
By default, change streams only return the delta of fields during the update operation.
Expand Down Expand Up @@ -225,10 +251,22 @@ update operation.
.. class:: copyable-code

.. literalinclude:: /driver-examples/test-mongoc-sample-commands.c
:language: C
:language: c
:dedent: 0
:start-after: Start Changestream Example 2
:end-before: End Changestream Example 2


- id: nodejs
content: |
.. class:: copyable-code

.. literalinclude:: /driver-examples/ChangeStreamNodeExamples.js
:language: nodejs
:dedent: 0
:start-after: Start Changestream Example 2
:end-before: End Changestream Eample 2


- id: ruby
content: |
Expand All @@ -240,6 +278,7 @@ update operation.
:start-after: Start Changestream Example 2
:end-before: End Changestream Example 2


See :ref:`change-stream-output` for more information on the change stream
response document format.

Expand Down Expand Up @@ -387,7 +426,22 @@ Resume a Change Stream
:start-after: Start Changestream Example 3
:end-before: End Changestream Example 3

- id: ruby

- id: nodejs
content: |
In the example below, the ``resumeAfter`` option is appended to the stream options
to recreate the stream after it has been destroyed. Passing the ``_id` to
the change stream attempts to resume notifications starting at the
operation specified.

.. class:: copyable-code

.. literalinclude:: /driver-examples/ChangeStreamNodeExamples.js
:language: nodejs
:dedent: 0
:start-after: Start Changestream Example 3
:end-before: End Changestream Example 3
- id: ruby
content: |
Each change stream response document has an ``_id`` field which can be passed
to the ``watch()`` method, indicating to the method at what point in the
Expand Down