Skip to content

Commit 25a3fe9

Browse files
committed
DOCS-13527: swift driver examples for change events and causal consistency
1 parent 05234ef commit 25a3fe9

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,10 @@ examples:
145145
# go
146146
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-go-driver/master/examples/documentation_examples/examples.go -o ${DRIVERS_PATH}/go_examples.go
147147

148+
# swift
149+
150+
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-swift-driver/master/Examples/Docs/Sources/AsyncExamples/main.swift -o ${DRIVERS_PATH}/swiftAsync.swift
151+
curl -SfL https://raw.githubusercontent.com/mongodb/mongo-swift-driver/master/Examples/Docs/Sources/SyncExamples/main.swift -o ${DRIVERS_PATH}/swiftSync.swift
152+
148153
changelogs:
149154
python changelogs/generatechangelogs.py

source/changeStreams.txt

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,38 @@ Open A Change Stream
250250
:start-after: Start Changestream Example 1
251251
:end-before: End Changestream Example 1
252252

253+
- id: swift-sync
254+
content: |
255+
256+
The Swift (Sync) examples below assume that you have
257+
`connected to a MongoDB replica set and have accessed a
258+
database
259+
<https://mongodb.github.io/mongo-swift-driver/MongoSwiftSync/Classes/MongoClient.html>`__
260+
that contains an ``inventory`` collection.
261+
262+
263+
.. literalinclude:: /driver-examples/swiftSync.swift
264+
:language: swift
265+
:dedent: 8
266+
:start-after: Start Changestream Example 1
267+
:end-before: End Changestream Example 1
268+
269+
- id: swift-async
270+
content: |
271+
272+
The Swift (Async) examples below assume that you have
273+
`connected to a MongoDB replica set and have accessed a
274+
database
275+
<https://mongodb.github.io/mongo-swift-driver/MongoSwift/Classes/MongoClient.html>`__
276+
that contains an ``inventory`` collection.
277+
278+
.. literalinclude:: /driver-examples/swiftAsync.swift
279+
:language: swift
280+
:dedent: 8
281+
:start-after: Start Changestream Example 1
282+
:end-before: End Changestream Example 1
283+
284+
253285
To retrieve the :ref:`data change event <change-stream-output>` from
254286
the cursor, iterate the change stream cursor. For information on the
255287
change stream event, see :ref:`change-stream-output`.
@@ -396,6 +428,29 @@ Modify Change Stream Output
396428
:start-after: Start Changestream Example 4
397429
:end-before: End Changestream Example 4
398430

431+
- id: swift-sync
432+
content: |
433+
434+
.. include:: /includes/fact-change-streams-modify-output.rst
435+
436+
.. literalinclude:: /driver-examples/swiftSync.swift
437+
:language: swift
438+
:dedent: 8
439+
:start-after: Start Changestream Example 4
440+
:end-before: End Changestream Example 4
441+
442+
- id: swift-async
443+
content: |
444+
445+
.. include:: /includes/fact-change-streams-modify-output.rst
446+
447+
.. literalinclude:: /driver-examples/swiftAsync.swift
448+
:language: swift
449+
:dedent: 8
450+
:start-after: Start Changestream Example 4
451+
:end-before: End Changestream Example 4
452+
453+
399454
.. tip::
400455

401456
The :ref:`_id <change-stream-event-id>` field of the change stream
@@ -586,6 +641,34 @@ Lookup Full Document for Update Operations
586641
:start-after: Start Changestream Example 2
587642
:end-before: End Changestream Example 2
588643

644+
- id: swift-sync
645+
content: |
646+
647+
To return the most current majority-committed version of
648+
the updated document, pass ``options:
649+
ChangeStreamOptions(fullDocument: .updateLookup)`` to the
650+
``watch()`` method.
651+
652+
.. literalinclude:: /driver-examples/swiftSync.swift
653+
:language: swift
654+
:dedent: 8
655+
:start-after: Start Changestream Example 2
656+
:end-before: End Changestream Example 2
657+
658+
- id: swift-async
659+
content: |
660+
661+
To return the most current majority-committed version of
662+
the updated document, pass ``options:
663+
ChangeStreamOptions(fullDocument: .updateLookup)`` to the
664+
``watch()`` method.
665+
666+
.. literalinclude:: /driver-examples/swiftAsync.swift
667+
:language: swift
668+
:dedent: 8
669+
:start-after: Start Changestream Example 2
670+
:end-before: End Changestream Example 2
671+
589672
.. note::
590673

591674
If there are one or more majority-committed operations that modified
@@ -782,6 +865,36 @@ Change streams are resumable by specifying a resume token to either
782865
:start-after: Start Changestream Example 3
783866
:end-before: End Changestream Example 3
784867

868+
- id: swift-sync
869+
content: |
870+
871+
You can use the ``resumeAfter`` option to resume
872+
notifications after the operation specified in the resume
873+
token. The ``resumeAfter`` option takes a value that must
874+
resolve to a resume token, e.g. ``resumeToken`` in the
875+
example below.
876+
877+
.. literalinclude:: /driver-examples/swiftSync.swift
878+
:language: swift
879+
:dedent: 8
880+
:start-after: Start Changestream Example 3
881+
:end-before: End Changestream Example 3
882+
883+
- id: swift-async
884+
content: |
885+
886+
You can use the ``resumeAfter`` option to resume
887+
notifications after the operation specified in the resume
888+
token. The ``resumeAfter`` option takes a value that must
889+
resolve to a resume token, e.g. ``resumeToken`` in the
890+
example below.
891+
892+
.. literalinclude:: /driver-examples/swiftAsync.swift
893+
:language: swift
894+
:dedent: 8
895+
:start-after: Start Changestream Example 3
896+
:end-before: End Changestream Example 3
897+
785898
.. _change-stream-start-after:
786899

787900
``startAfter`` for Change Streams

source/core/read-isolation-consistency-recency.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,25 @@ ensure that the update occurs before the insert.
351351
:start-after: Start Causal Consistency Example 1
352352
:end-before: End Causal Consistency Example 1
353353

354+
- id: swift-sync
355+
content: |
356+
357+
.. literalinclude:: /driver-examples/swiftSync.swift
358+
:language: swift
359+
:dedent: 4
360+
:start-after: Start Causal Consistency Example 1
361+
:end-before: End Causal Consistency Example 1
362+
363+
- id: swift-async
364+
content: |
365+
366+
.. literalinclude:: /driver-examples/swiftAsync.swift
367+
:language: swift
368+
:dedent: 4
369+
:start-after: Start Causal Consistency Example 1
370+
:end-before: End Causal Consistency Example 1
371+
372+
354373
If another client needs to read all current ``sku`` values, you can
355374
advance the cluster time and the operation time to that of the other
356375
session to ensure that this client is causally consistent with the
@@ -422,6 +441,24 @@ other session and read after the two writes:
422441
:start-after: Start Causal Consistency Example 2
423442
:end-before: End Causal Consistency Example 2
424443

444+
- id: swift-sync
445+
content: |
446+
447+
.. literalinclude:: /driver-examples/swiftSync.swift
448+
:language: swift
449+
:dedent: 4
450+
:start-after: Start Causal Consistency Example 2
451+
:end-before: End Causal Consistency Example 2
452+
453+
- id: swift-async
454+
content: |
455+
456+
.. literalinclude:: /driver-examples/swiftAsync.swift
457+
:language: swift
458+
:dedent: 4
459+
:start-after: Start Causal Consistency Example 2
460+
:end-before: End Causal Consistency Example 2
461+
425462
.. _causal-consistency-limitations:
426463

427464
Limitations

source/release-notes/4.4.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,16 @@ Platform Support
604604

605605
See :ref:`prod-notes-supported-platforms`.
606606

607+
Drivers
608+
-------
609+
610+
New Drivers
611+
~~~~~~~~~~~
612+
613+
The official `MongoDB Swift driver
614+
<https://github.com/mongodb/mongo-swift-driver>`__ is now available.
615+
616+
607617
Tools
608618
-----
609619

0 commit comments

Comments
 (0)