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
ff9d54c2
Commit
ff9d54c2
authored
Dec 23, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69
parents
006f3000
880f45be
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
3 deletions
+46
-3
Collection.php
src/Collection.php
+20
-3
FindAndModify.php
src/Operation/FindAndModify.php
+13
-0
FindOneAndDelete.php
src/Operation/FindOneAndDelete.php
+3
-0
FindOneAndReplace.php
src/Operation/FindOneAndReplace.php
+3
-0
FindOneAndUpdate.php
src/Operation/FindOneAndUpdate.php
+3
-0
FindAndModifyTest.php
tests/Operation/FindAndModifyTest.php
+4
-0
No files found.
src/Collection.php
View file @
ff9d54c2
...
@@ -37,6 +37,8 @@ use Traversable;
...
@@ -37,6 +37,8 @@ use Traversable;
class
Collection
class
Collection
{
{
private
static
$wireVersionForFindAndModifyWriteConcern
=
4
;
private
$collectionName
;
private
$collectionName
;
private
$databaseName
;
private
$databaseName
;
private
$manager
;
private
$manager
;
...
@@ -394,9 +396,14 @@ class Collection
...
@@ -394,9 +396,14 @@ class Collection
*/
*/
public
function
findOneAndDelete
(
$filter
,
array
$options
=
[])
public
function
findOneAndDelete
(
$filter
,
array
$options
=
[])
{
{
$operation
=
new
FindOneAndDelete
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
if
(
!
isset
(
$options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModifyWriteConcern
))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
}
$operation
=
new
FindOneAndDelete
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
return
$operation
->
execute
(
$server
);
return
$operation
->
execute
(
$server
);
}
}
...
@@ -417,9 +424,14 @@ class Collection
...
@@ -417,9 +424,14 @@ class Collection
*/
*/
public
function
findOneAndReplace
(
$filter
,
$replacement
,
array
$options
=
[])
public
function
findOneAndReplace
(
$filter
,
$replacement
,
array
$options
=
[])
{
{
$operation
=
new
FindOneAndReplace
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$replacement
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
if
(
!
isset
(
$options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModifyWriteConcern
))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
}
$operation
=
new
FindOneAndReplace
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$replacement
,
$options
);
return
$operation
->
execute
(
$server
);
return
$operation
->
execute
(
$server
);
}
}
...
@@ -440,9 +452,14 @@ class Collection
...
@@ -440,9 +452,14 @@ class Collection
*/
*/
public
function
findOneAndUpdate
(
$filter
,
$update
,
array
$options
=
[])
public
function
findOneAndUpdate
(
$filter
,
$update
,
array
$options
=
[])
{
{
$operation
=
new
FindOneAndUpdate
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$update
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
if
(
!
isset
(
$options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModifyWriteConcern
))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
}
$operation
=
new
FindOneAndUpdate
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$update
,
$options
);
return
$operation
->
execute
(
$server
);
return
$operation
->
execute
(
$server
);
}
}
...
...
src/Operation/FindAndModify.php
View file @
ff9d54c2
...
@@ -4,6 +4,7 @@ namespace MongoDB\Operation;
...
@@ -4,6 +4,7 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Exception\UnexpectedValueException
;
...
@@ -20,6 +21,7 @@ use MongoDB\Exception\UnexpectedValueException;
...
@@ -20,6 +21,7 @@ use MongoDB\Exception\UnexpectedValueException;
class
FindAndModify
implements
Executable
class
FindAndModify
implements
Executable
{
{
private
static
$wireVersionForDocumentLevelValidation
=
4
;
private
static
$wireVersionForDocumentLevelValidation
=
4
;
private
static
$wireVersionForWriteConcern
=
4
;
private
$databaseName
;
private
$databaseName
;
private
$collectionName
;
private
$collectionName
;
...
@@ -58,6 +60,9 @@ class FindAndModify implements Executable
...
@@ -58,6 +60,9 @@ class FindAndModify implements Executable
* matches the query. This option is ignored for remove operations. The
* matches the query. This option is ignored for remove operations. The
* default is false.
* default is false.
*
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
* is only supported for server versions >= 3.2.
*
* @param string $databaseName Database name
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param string $collectionName Collection name
* @param array $options Command options
* @param array $options Command options
...
@@ -103,6 +108,10 @@ class FindAndModify implements Executable
...
@@ -103,6 +108,10 @@ class FindAndModify implements Executable
throw
new
InvalidArgumentTypeException
(
'"update" option'
,
$options
[
'update'
],
'array or object'
);
throw
new
InvalidArgumentTypeException
(
'"update" option'
,
$options
[
'update'
],
'array or object'
);
}
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
!
$options
[
'writeConcern'
]
instanceof
WriteConcern
)
{
throw
new
InvalidArgumentTypeException
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
!
is_bool
(
$options
[
'upsert'
]))
{
if
(
!
is_bool
(
$options
[
'upsert'
]))
{
throw
new
InvalidArgumentTypeException
(
'"upsert" option'
,
$options
[
'upsert'
],
'boolean'
);
throw
new
InvalidArgumentTypeException
(
'"upsert" option'
,
$options
[
'upsert'
],
'boolean'
);
}
}
...
@@ -181,6 +190,10 @@ class FindAndModify implements Executable
...
@@ -181,6 +190,10 @@ class FindAndModify implements Executable
$cmd
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
$cmd
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
}
if
(
isset
(
$this
->
options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForWriteConcern
))
{
$cmd
[
'writeConcern'
]
=
$this
->
options
[
'writeConcern'
];
}
return
new
Command
(
$cmd
);
return
new
Command
(
$cmd
);
}
}
}
}
src/Operation/FindOneAndDelete.php
View file @
ff9d54c2
...
@@ -32,6 +32,9 @@ class FindOneAndDelete implements Executable
...
@@ -32,6 +32,9 @@ class FindOneAndDelete implements Executable
* * sort (document): Determines which document the operation modifies if
* * sort (document): Determines which document the operation modifies if
* the query selects multiple documents.
* the query selects multiple documents.
*
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
* is only supported for server versions >= 3.2.
*
* @param string $databaseName Database name
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param string $collectionName Collection name
* @param array|object $filter Query by which to filter documents
* @param array|object $filter Query by which to filter documents
...
...
src/Operation/FindOneAndReplace.php
View file @
ff9d54c2
...
@@ -45,6 +45,9 @@ class FindOneAndReplace implements Executable
...
@@ -45,6 +45,9 @@ class FindOneAndReplace implements Executable
* * upsert (boolean): When true, a new document is created if no document
* * upsert (boolean): When true, a new document is created if no document
* matches the query. The default is false.
* matches the query. The default is false.
*
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
* is only supported for server versions >= 3.2.
*
* @param string $databaseName Database name
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param string $collectionName Collection name
* @param array|object $filter Query by which to filter documents
* @param array|object $filter Query by which to filter documents
...
...
src/Operation/FindOneAndUpdate.php
View file @
ff9d54c2
...
@@ -45,6 +45,9 @@ class FindOneAndUpdate implements Executable
...
@@ -45,6 +45,9 @@ class FindOneAndUpdate implements Executable
* * upsert (boolean): When true, a new document is created if no document
* * upsert (boolean): When true, a new document is created if no document
* matches the query. The default is false.
* matches the query. The default is false.
*
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
* is only supported for server versions >= 3.2.
*
* @param string $databaseName Database name
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param string $collectionName Collection name
* @param array|object $filter Query by which to filter documents
* @param array|object $filter Query by which to filter documents
...
...
tests/Operation/FindAndModifyTest.php
View file @
ff9d54c2
...
@@ -55,6 +55,10 @@ class FindAndModifyTest extends TestCase
...
@@ -55,6 +55,10 @@ class FindAndModifyTest extends TestCase
$options
[][]
=
[
'upsert'
=>
$value
];
$options
[][]
=
[
'upsert'
=>
$value
];
}
}
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
[
'writeConcern'
=>
$value
];
}
return
$options
;
return
$options
;
}
}
...
...
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