From 0e8f539cad32d5045a8fbf69f59f08c150d8c22d Mon Sep 17 00:00:00 2001 From: skerschb Date: Fri, 5 Jan 2018 14:59:03 -0500 Subject: [PATCH 1/3] DOCSP-1505 adding node examples --- Makefile | 1 + source/tutorial/change-streams-example.txt | 51 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a9675dddd6e..298c1623b14 100644 --- a/Makefile +++ b/Makefile @@ -94,6 +94,7 @@ examples: curl -SfL https://raw.githubusercontent.com/mongodb/mongo-ruby-driver/master/spec/mongo/shell_examples_spec.rb -o ${DRIVERS_PATH}/shell_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 diff --git a/source/tutorial/change-streams-example.txt b/source/tutorial/change-streams-example.txt index 81cf98d979b..885c16ed999 100644 --- a/source/tutorial/change-streams-example.txt +++ b/source/tutorial/change-streams-example.txt @@ -55,6 +55,12 @@ Change Stream Examples The examples below assume that you have `connected to a MongoDB replica set and have accessed a database `__ that contains an ``inventory`` collection. + + - id: node + content: | + The examples below assume that you have `connected to a MongoDB replica set and have accessed a database + `_ + that contains an ``inventory`` collection. Open A Change Stream -------------------- @@ -104,6 +110,17 @@ as long as a connection to the MongoDB deployment remains open *and* the collect :dedent: 0 :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 In order to retrieve the data change event notifications, iterate the change stream ``cursor``. @@ -147,6 +164,13 @@ Lookup Full Document for Update Operations To return the most current majority-committed version of the updated 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. If there are one or more majority-committed operations that modified the @@ -202,11 +226,21 @@ 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 + See :ref:`change-stream-output` for more information on the change stream response document format. @@ -336,6 +370,21 @@ notification after a specific notification. :dedent: 0 :start-after: Start Changestream Example 3 :end-before: End Changestream Example 3 + + - 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 As long as that operation has not rolled off the :term:`oplog`, the From 7725c20b4f66d0f035db20965cced4a22db6c0ab Mon Sep 17 00:00:00 2001 From: skerschb Date: Mon, 22 Jan 2018 09:46:36 -0500 Subject: [PATCH 2/3] merge fix --- source/tutorial/change-streams-example.txt | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/source/tutorial/change-streams-example.txt b/source/tutorial/change-streams-example.txt index 885c16ed999..10cd2aea7f8 100644 --- a/source/tutorial/change-streams-example.txt +++ b/source/tutorial/change-streams-example.txt @@ -28,39 +28,54 @@ 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 - `__ + The Python examples below assume that you have `connected to a MongoDB replica set and have accessed a database + `_ 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 - `__ + The Java examples below assume that you have `connected to a MongoDB replica set and have accessed a database + `_ 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 - `__ - that contains an ``inventory`` collection. + The C# examples below assume that you have `connected to a MongoDB replica set and have accessed a database + `_ + 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 - `__ + The C examples below assume that you have `connected to a MongoDB replica set and have accessed a database + `_ that contains an ``inventory`` collection. - - id: node + - id: nodejs content: | - The examples below assume that you have `connected to a MongoDB replica set and have accessed a database + The Node.js examples below assume that you have `connected to a MongoDB replica set and have accessed a database `_ that contains an ``inventory`` collection. + + +.. important:: + Change streams are available for replica sets or sharded clusters with replica set + shards. You cannot open a change stream against a standalone :program:`mongod`. + For a sharded cluster, you must issue the open change stream operation against + the :program:`mongos`. + + The replica set or the sharded cluster must use: + + - replica set protocol version 1 (:rsconf:`pv1 `) + + - :ref:`WiredTiger ` storage engine (can be :ref:`encrypted `) + + Open A Change Stream -------------------- From 7706ad00d14f14e6652dc5198acf2555b24a1ded Mon Sep 17 00:00:00 2001 From: skerschb Date: Wed, 17 Jan 2018 10:03:28 -0500 Subject: [PATCH 3/3] DOCSP-1505: added language to clarify selected tab --- source/tutorial/change-streams-example.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tutorial/change-streams-example.txt b/source/tutorial/change-streams-example.txt index 10cd2aea7f8..5f1f967acf3 100644 --- a/source/tutorial/change-streams-example.txt +++ b/source/tutorial/change-streams-example.txt @@ -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: