Skip to content

Commit 7d7a5ba

Browse files
committed
PHPLIB-302: Support session option for change streams
1 parent e85d3b3 commit 7d7a5ba

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/includes/apiargs-MongoDBCollection-method-watch-option.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ description: |
6666
interface: phpmethod
6767
operation: ~
6868
optional: true
69+
---
70+
source:
71+
file: apiargs-common-option.yaml
72+
ref: session
6973
...

src/Operation/Watch.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ class Watch implements Executable
6767
* Insert and replace operations always include the "fullDocument" field
6868
* and delete operations omit the field as the document no longer exists.
6969
*
70-
* * session (MongoDB\Driver\Session): Client session.
71-
*
72-
* Sessions are not supported for server versions < 3.6.
73-
*
7470
* * maxAwaitTimeMS (integer): The maximum amount of time for the server to
7571
* wait on new documents to satisfy a change stream query.
7672
*
@@ -83,6 +79,10 @@ class Watch implements Executable
8379
* * resumeAfter (document): Specifies the logical starting point for the
8480
* new change stream.
8581
*
82+
* * session (MongoDB\Driver\Session): Client session.
83+
*
84+
* Sessions are not supported for server versions < 3.6.
85+
*
8686
* @param string $databaseName Database name
8787
* @param string $collectionName Collection name
8888
* @param array $pipeline List of pipeline operations
@@ -148,7 +148,7 @@ private function createAggregate()
148148
$pipeline = $this->pipeline;
149149
array_unshift($pipeline, $changeStream);
150150

151-
$aggregateOptions = array_intersect_key($this->options, ['batchSize' => 1, 'collation' => 1, 'maxAwaitTimeMS' => 1, 'readConcern' => 1, 'readPreference' => 1]);
151+
$aggregateOptions = array_intersect_key($this->options, ['batchSize' => 1, 'collation' => 1, 'maxAwaitTimeMS' => 1, 'readConcern' => 1, 'readPreference' => 1, 'session' => 1]);
152152

153153
return new Aggregate($this->databaseName, $this->collectionName, $pipeline, $aggregateOptions);
154154
}

tests/Operation/WatchTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function provideInvalidConstructorOptions()
6363
$options[][] = ['resumeAfter' => $value];
6464
}
6565

66+
foreach ($this->getInvalidSessionValues() as $value) {
67+
$options[][] = ['session' => $value];
68+
}
69+
6670
return $options;
6771
}
6872
}

0 commit comments

Comments
 (0)