Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
80cee6f6
Commit
80cee6f6
authored
Jul 09, 2019
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #637
parents
4fc1f90b
d49ab3ab
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
137 additions
and
9 deletions
+137
-9
apiargs-MongoDBClient-method-watch-option.yaml
docs/includes/apiargs-MongoDBClient-method-watch-option.yaml
+6
-0
apiargs-MongoDBCollection-method-watch-option.yaml
...cludes/apiargs-MongoDBCollection-method-watch-option.yaml
+6
-0
apiargs-MongoDBDatabase-method-watch-option.yaml
...includes/apiargs-MongoDBDatabase-method-watch-option.yaml
+6
-0
apiargs-method-watch-option.yaml
docs/includes/apiargs-method-watch-option.yaml
+28
-4
Watch.php
src/Operation/Watch.php
+19
-5
WatchFunctionalTest.php
tests/Operation/WatchFunctionalTest.php
+72
-0
No files found.
docs/includes/apiargs-MongoDBClient-method-watch-option.yaml
View file @
80cee6f6
...
@@ -34,6 +34,12 @@ source:
...
@@ -34,6 +34,12 @@ source:
file
:
apiargs-common-option.yaml
file
:
apiargs-common-option.yaml
ref
:
session
ref
:
session
---
---
source
:
file
:
apiargs-method-watch-option.yaml
ref
:
startAfter
post
:
|
.. versionadded: 1.5
---
source
:
source
:
file
:
apiargs-method-watch-option.yaml
file
:
apiargs-method-watch-option.yaml
ref
:
startAtOperationTime
ref
:
startAtOperationTime
...
...
docs/includes/apiargs-MongoDBCollection-method-watch-option.yaml
View file @
80cee6f6
...
@@ -34,6 +34,12 @@ source:
...
@@ -34,6 +34,12 @@ source:
file
:
apiargs-common-option.yaml
file
:
apiargs-common-option.yaml
ref
:
session
ref
:
session
---
---
source
:
file
:
apiargs-method-watch-option.yaml
ref
:
startAfter
post
:
|
.. versionadded: 1.5
---
source
:
source
:
file
:
apiargs-method-watch-option.yaml
file
:
apiargs-method-watch-option.yaml
ref
:
startAtOperationTime
ref
:
startAtOperationTime
...
...
docs/includes/apiargs-MongoDBDatabase-method-watch-option.yaml
View file @
80cee6f6
...
@@ -34,6 +34,12 @@ source:
...
@@ -34,6 +34,12 @@ source:
file
:
apiargs-common-option.yaml
file
:
apiargs-common-option.yaml
ref
:
session
ref
:
session
---
---
source
:
file
:
apiargs-method-watch-option.yaml
ref
:
startAfter
post
:
|
.. versionadded: 1.5
---
source
:
source
:
file
:
apiargs-method-watch-option.yaml
file
:
apiargs-method-watch-option.yaml
ref
:
startAtOperationTime
ref
:
startAtOperationTime
...
...
docs/includes/apiargs-method-watch-option.yaml
View file @
80cee6f6
...
@@ -46,8 +46,32 @@ description: |
...
@@ -46,8 +46,32 @@ description: |
Specifies the logical starting point for the new change stream. The ``_id``
Specifies the logical starting point for the new change stream. The ``_id``
field in documents returned by the change stream may be used here.
field in documents returned by the change stream may be used here.
Using this option in conjunction with ``startAtOperationTime`` will result in
Using this option in conjunction with ``startAfter`` and/or
a server error. The options are mutually exclusive.
``startAtOperationTime`` will result in a server error. The options are
mutually exclusive.
.. note::
This is an option of the ``$changeStream`` pipeline stage.
interface
:
phpmethod
operation
:
~
optional
:
true
---
arg_name
:
option
name
:
startAfter
type
:
array|object
description
:
|
Specifies the logical starting point for the new change stream. The ``_id``
field in documents returned by the change stream may be used here. Unlike
``resumeAfter``, this option can be used with a resume token from an
"invalidate" event.
Using this option in conjunction with ``resumeAfter`` and/or
``startAtOperationTime`` will result in a server error. The options are
mutually exclusive.
This is not supported for server versions prior to 4.2 and will result in an
exception at execution time if used.
.. note::
.. note::
...
@@ -66,8 +90,8 @@ description: |
...
@@ -66,8 +90,8 @@ description: |
``operationTime`` returned by the initial ``aggregate`` command will be used
``operationTime`` returned by the initial ``aggregate`` command will be used
if available.
if available.
Using this option in conjunction with ``resumeAfter``
will result in a server
Using this option in conjunction with ``resumeAfter``
and/or ``startAfter``
error. The options are mutually exclusive.
will result in a server
error. The options are mutually exclusive.
This is not supported for server versions prior to 4.0 and will result in an
This is not supported for server versions prior to 4.0 and will result in an
exception at execution time if used.
exception at execution time if used.
...
...
src/Operation/Watch.php
View file @
80cee6f6
...
@@ -92,21 +92,31 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
...
@@ -92,21 +92,31 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
* * resumeAfter (document): Specifies the logical starting point for the
* * resumeAfter (document): Specifies the logical starting point for the
* new change stream.
* new change stream.
*
*
* Using this option in conjunction with "startAtOperationTime" will
* Using this option in conjunction with "startAfter" and/or
* result in a server error. The options are mutually exclusive.
* "startAtOperationTime" will result in a server error. The options are
* mutually exclusive.
*
*
* * session (MongoDB\Driver\Session): Client session.
* * session (MongoDB\Driver\Session): Client session.
*
*
* Sessions are not supported for server versions < 3.6.
* Sessions are not supported for server versions < 3.6.
*
*
* * startAfter (document): Specifies the logical starting point for the
* new change stream. Unlike "resumeAfter", this option can be used with
* a resume token from an "invalidate" event.
*
* Using this option in conjunction with "resumeAfter" and/or
* "startAtOperationTime" will result in a server error. The options are
* mutually exclusive.
*
* * startAtOperationTime (MongoDB\BSON\TimestampInterface): If specified,
* * startAtOperationTime (MongoDB\BSON\TimestampInterface): If specified,
* the change stream will only provide changes that occurred at or after
* the change stream will only provide changes that occurred at or after
* the specified timestamp. Any command run against the server will
* the specified timestamp. Any command run against the server will
* return an operation time that can be used here. Alternatively, an
* return an operation time that can be used here. Alternatively, an
* operation time may be obtained from MongoDB\Driver\Server::getInfo().
* operation time may be obtained from MongoDB\Driver\Server::getInfo().
*
*
* Using this option in conjunction with "resumeAfter" will result in a
* Using this option in conjunction with "resumeAfter" and/or
* server error. The options are mutually exclusive.
* "startAfter" will result in a server error. The options are mutually
* exclusive.
*
*
* This option is not supported for server versions < 4.0.
* This option is not supported for server versions < 4.0.
*
*
...
@@ -143,6 +153,10 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
...
@@ -143,6 +153,10 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
throw
InvalidArgumentException
::
invalidType
(
'"resumeAfter" option'
,
$options
[
'resumeAfter'
],
'array or object'
);
throw
InvalidArgumentException
::
invalidType
(
'"resumeAfter" option'
,
$options
[
'resumeAfter'
],
'array or object'
);
}
}
if
(
isset
(
$options
[
'startAfter'
])
&&
!
is_array
(
$options
[
'startAfter'
])
&&
!
is_object
(
$options
[
'startAfter'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"startAfter" option'
,
$options
[
'startAfter'
],
'array or object'
);
}
if
(
isset
(
$options
[
'startAtOperationTime'
])
&&
!
$options
[
'startAtOperationTime'
]
instanceof
TimestampInterface
)
{
if
(
isset
(
$options
[
'startAtOperationTime'
])
&&
!
$options
[
'startAtOperationTime'
]
instanceof
TimestampInterface
)
{
throw
InvalidArgumentException
::
invalidType
(
'"startAtOperationTime" option'
,
$options
[
'startAtOperationTime'
],
TimestampInterface
::
class
);
throw
InvalidArgumentException
::
invalidType
(
'"startAtOperationTime" option'
,
$options
[
'startAtOperationTime'
],
TimestampInterface
::
class
);
}
}
...
@@ -162,7 +176,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
...
@@ -162,7 +176,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
}
}
$this
->
aggregateOptions
=
array_intersect_key
(
$options
,
[
'batchSize'
=>
1
,
'collation'
=>
1
,
'maxAwaitTimeMS'
=>
1
,
'readConcern'
=>
1
,
'readPreference'
=>
1
,
'session'
=>
1
,
'typeMap'
=>
1
]);
$this
->
aggregateOptions
=
array_intersect_key
(
$options
,
[
'batchSize'
=>
1
,
'collation'
=>
1
,
'maxAwaitTimeMS'
=>
1
,
'readConcern'
=>
1
,
'readPreference'
=>
1
,
'session'
=>
1
,
'typeMap'
=>
1
]);
$this
->
changeStreamOptions
=
array_intersect_key
(
$options
,
[
'fullDocument'
=>
1
,
'resumeAfter'
=>
1
,
'startAtOperationTime'
=>
1
]);
$this
->
changeStreamOptions
=
array_intersect_key
(
$options
,
[
'fullDocument'
=>
1
,
'resumeAfter'
=>
1
,
'startA
fter'
=>
1
,
'startA
tOperationTime'
=>
1
]);
// Null database name implies a cluster-wide change stream
// Null database name implies a cluster-wide change stream
if
(
$databaseName
===
null
)
{
if
(
$databaseName
===
null
)
{
...
...
tests/Operation/WatchFunctionalTest.php
View file @
80cee6f6
...
@@ -759,6 +759,78 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -759,6 +759,78 @@ class WatchFunctionalTest extends FunctionalTestCase
$this
->
assertMatchesDocument
(
$expectedResult
,
$changeStream
->
current
());
$this
->
assertMatchesDocument
(
$expectedResult
,
$changeStream
->
current
());
}
}
public
function
testResumeAfterOption
()
{
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
->
rewind
();
$this
->
assertFalse
(
$changeStream
->
valid
());
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
$this
->
insertDocument
([
'_id'
=>
2
,
'x'
=>
'bar'
]);
$changeStream
->
next
();
$this
->
assertTrue
(
$changeStream
->
valid
());
$resumeToken
=
$changeStream
->
current
()
->
_id
;
$options
=
$this
->
defaultOptions
+
[
'resumeAfter'
=>
$resumeToken
];
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$options
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
->
rewind
();
$this
->
assertTrue
(
$changeStream
->
valid
());
$expectedResult
=
[
'_id'
=>
$changeStream
->
current
()
->
_id
,
'operationType'
=>
'insert'
,
'fullDocument'
=>
[
'_id'
=>
2
,
'x'
=>
'bar'
],
'ns'
=>
[
'db'
=>
$this
->
getDatabaseName
(),
'coll'
=>
$this
->
getCollectionName
()],
'documentKey'
=>
[
'_id'
=>
2
],
];
$this
->
assertMatchesDocument
(
$expectedResult
,
$changeStream
->
current
());
}
public
function
testStartAfterOption
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'4.1.1'
,
'<'
))
{
$this
->
markTestSkipped
(
'startAfter is not supported'
);
}
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
->
rewind
();
$this
->
assertFalse
(
$changeStream
->
valid
());
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
$this
->
insertDocument
([
'_id'
=>
2
,
'x'
=>
'bar'
]);
$changeStream
->
next
();
$this
->
assertTrue
(
$changeStream
->
valid
());
$resumeToken
=
$changeStream
->
current
()
->
_id
;
$options
=
$this
->
defaultOptions
+
[
'startAfter'
=>
$resumeToken
];
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$options
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
->
rewind
();
$this
->
assertTrue
(
$changeStream
->
valid
());
$expectedResult
=
[
'_id'
=>
$changeStream
->
current
()
->
_id
,
'operationType'
=>
'insert'
,
'fullDocument'
=>
[
'_id'
=>
2
,
'x'
=>
'bar'
],
'ns'
=>
[
'db'
=>
$this
->
getDatabaseName
(),
'coll'
=>
$this
->
getCollectionName
()],
'documentKey'
=>
[
'_id'
=>
2
],
];
$this
->
assertMatchesDocument
(
$expectedResult
,
$changeStream
->
current
());
}
/**
/**
* @dataProvider provideTypeMapOptionsAndExpectedChangeDocument
* @dataProvider provideTypeMapOptionsAndExpectedChangeDocument
*/
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment