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
1eebfe0d
Commit
1eebfe0d
authored
Feb 23, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getCommandDocument for DeleteOne, DeleteMany, UpdateOne, and UpdateMany
parent
0f91e9f3
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
119 additions
and
25 deletions
+119
-25
Count.php
src/Operation/Count.php
+1
-1
Delete.php
src/Operation/Delete.php
+1
-1
DeleteMany.php
src/Operation/DeleteMany.php
+6
-1
DeleteOne.php
src/Operation/DeleteOne.php
+6
-1
Distinct.php
src/Operation/Distinct.php
+1
-1
Explain.php
src/Operation/Explain.php
+1
-1
Explainable.php
src/Operation/Explainable.php
+3
-1
Find.php
src/Operation/Find.php
+1
-1
FindAndModify.php
src/Operation/FindAndModify.php
+4
-4
FindOne.php
src/Operation/FindOne.php
+2
-2
FindOneAndDelete.php
src/Operation/FindOneAndDelete.php
+2
-2
FindOneAndReplace.php
src/Operation/FindOneAndReplace.php
+2
-2
FindOneAndUpdate.php
src/Operation/FindOneAndUpdate.php
+2
-2
Update.php
src/Operation/Update.php
+1
-1
UpdateMany.php
src/Operation/UpdateMany.php
+6
-1
UpdateOne.php
src/Operation/UpdateOne.php
+6
-1
ExplainFunctionalTest.php
tests/Operation/ExplainFunctionalTest.php
+74
-2
No files found.
src/Operation/Count.php
View file @
1eebfe0d
...
@@ -162,7 +162,7 @@ class Count implements Executable, Explainable
...
@@ -162,7 +162,7 @@ class Count implements Executable, Explainable
return
(
integer
)
$result
->
n
;
return
(
integer
)
$result
->
n
;
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
createCommandDocument
();
return
$this
->
createCommandDocument
();
}
}
...
...
src/Operation/Delete.php
View file @
1eebfe0d
...
@@ -125,7 +125,7 @@ class Delete implements Executable, Explainable
...
@@ -125,7 +125,7 @@ class Delete implements Executable, Explainable
return
new
DeleteResult
(
$writeResult
);
return
new
DeleteResult
(
$writeResult
);
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
$cmd
=
[
'delete'
=>
$this
->
collectionName
,
'deletes'
=>
[[
'q'
=>
$this
->
filter
]
+
$this
->
createDeleteOptions
()]];
$cmd
=
[
'delete'
=>
$this
->
collectionName
,
'deletes'
=>
[[
'q'
=>
$this
->
filter
]
+
$this
->
createDeleteOptions
()]];
...
...
src/Operation/DeleteMany.php
View file @
1eebfe0d
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
* @see \MongoDB\Collection::deleteOne()
* @see \MongoDB\Collection::deleteOne()
* @see http://docs.mongodb.org/manual/reference/command/delete/
* @see http://docs.mongodb.org/manual/reference/command/delete/
*/
*/
class
DeleteMany
implements
Executable
class
DeleteMany
implements
Executable
,
Explainable
{
{
private
$delete
;
private
$delete
;
...
@@ -74,4 +74,9 @@ class DeleteMany implements Executable
...
@@ -74,4 +74,9 @@ class DeleteMany implements Executable
{
{
return
$this
->
delete
->
execute
(
$server
);
return
$this
->
delete
->
execute
(
$server
);
}
}
public
function
getCommandDocument
(
Server
$server
)
{
return
$this
->
delete
->
getCommandDocument
(
$server
);
}
}
}
src/Operation/DeleteOne.php
View file @
1eebfe0d
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
* @see \MongoDB\Collection::deleteOne()
* @see \MongoDB\Collection::deleteOne()
* @see http://docs.mongodb.org/manual/reference/command/delete/
* @see http://docs.mongodb.org/manual/reference/command/delete/
*/
*/
class
DeleteOne
implements
Executable
class
DeleteOne
implements
Executable
,
Explainable
{
{
private
$delete
;
private
$delete
;
...
@@ -74,4 +74,9 @@ class DeleteOne implements Executable
...
@@ -74,4 +74,9 @@ class DeleteOne implements Executable
{
{
return
$this
->
delete
->
execute
(
$server
);
return
$this
->
delete
->
execute
(
$server
);
}
}
public
function
getCommandDocument
(
Server
$server
)
{
return
$this
->
delete
->
getCommandDocument
(
$server
);
}
}
}
src/Operation/Distinct.php
View file @
1eebfe0d
...
@@ -143,7 +143,7 @@ class Distinct implements Executable, Explainable
...
@@ -143,7 +143,7 @@ class Distinct implements Executable, Explainable
return
$result
->
values
;
return
$result
->
values
;
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
createCommandDocument
();
return
$this
->
createCommandDocument
();
}
}
...
...
src/Operation/Explain.php
View file @
1eebfe0d
...
@@ -88,7 +88,7 @@ class Explain implements Executable
...
@@ -88,7 +88,7 @@ class Explain implements Executable
throw
UnsupportedException
::
explainNotSupported
();
throw
UnsupportedException
::
explainNotSupported
();
}
}
$cmd
=
[
'explain'
=>
$this
->
explainable
->
getCommandDocument
()];
$cmd
=
[
'explain'
=>
$this
->
explainable
->
getCommandDocument
(
$server
)];
if
(
isset
(
$this
->
options
[
'verbosity'
]))
{
if
(
isset
(
$this
->
options
[
'verbosity'
]))
{
$cmd
[
'verbosity'
]
=
$this
->
options
[
'verbosity'
];
$cmd
[
'verbosity'
]
=
$this
->
options
[
'verbosity'
];
...
...
src/Operation/Explainable.php
View file @
1eebfe0d
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
namespace
MongoDB\Operation
;
namespace
MongoDB\Operation
;
use
MongoDB\Driver\Server
;
/**
/**
* Explainable interface for explainable operations (count, distinct, find,
* Explainable interface for explainable operations (count, distinct, find,
* findAndModify, delete, and update).
* findAndModify, delete, and update).
...
@@ -25,5 +27,5 @@ namespace MongoDB\Operation;
...
@@ -25,5 +27,5 @@ namespace MongoDB\Operation;
*/
*/
interface
Explainable
extends
Executable
interface
Explainable
extends
Executable
{
{
function
getCommandDocument
();
function
getCommandDocument
(
Server
$server
);
}
}
src/Operation/Find.php
View file @
1eebfe0d
...
@@ -293,7 +293,7 @@ class Find implements Executable, Explainable
...
@@ -293,7 +293,7 @@ class Find implements Executable, Explainable
return
$cursor
;
return
$cursor
;
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
createCommandDocument
();
return
$this
->
createCommandDocument
();
}
}
...
...
src/Operation/FindAndModify.php
View file @
1eebfe0d
...
@@ -210,7 +210,7 @@ class FindAndModify implements Executable, Explainable
...
@@ -210,7 +210,7 @@ class FindAndModify implements Executable, Explainable
throw
UnsupportedException
::
writeConcernNotSupported
();
throw
UnsupportedException
::
writeConcernNotSupported
();
}
}
$cursor
=
$server
->
executeReadWriteCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$cursor
=
$server
->
executeReadWriteCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
(
$server
)),
$this
->
createOptions
());
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
!
isset
(
$result
->
value
))
{
if
(
!
isset
(
$result
->
value
))
{
...
@@ -239,9 +239,9 @@ class FindAndModify implements Executable, Explainable
...
@@ -239,9 +239,9 @@ class FindAndModify implements Executable, Explainable
return
$result
->
value
;
return
$result
->
value
;
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
createCommandDocument
();
return
$this
->
createCommandDocument
(
$server
);
}
}
/**
/**
...
@@ -249,7 +249,7 @@ class FindAndModify implements Executable, Explainable
...
@@ -249,7 +249,7 @@ class FindAndModify implements Executable, Explainable
*
*
* @return array
* @return array
*/
*/
private
function
createCommandDocument
()
private
function
createCommandDocument
(
Server
$server
)
{
{
$cmd
=
[
'findAndModify'
=>
$this
->
collectionName
];
$cmd
=
[
'findAndModify'
=>
$this
->
collectionName
];
...
...
src/Operation/FindOne.php
View file @
1eebfe0d
...
@@ -127,8 +127,8 @@ class FindOne implements Executable, Explainable
...
@@ -127,8 +127,8 @@ class FindOne implements Executable, Explainable
return
(
$document
===
false
)
?
null
:
$document
;
return
(
$document
===
false
)
?
null
:
$document
;
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
find
->
getCommandDocument
();
return
$this
->
find
->
getCommandDocument
(
$server
);
}
}
}
}
src/Operation/FindOneAndDelete.php
View file @
1eebfe0d
...
@@ -106,8 +106,8 @@ class FindOneAndDelete implements Executable, Explainable
...
@@ -106,8 +106,8 @@ class FindOneAndDelete implements Executable, Explainable
return
$this
->
findAndModify
->
execute
(
$server
);
return
$this
->
findAndModify
->
execute
(
$server
);
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
findAndModify
->
getCommandDocument
();
return
$this
->
findAndModify
->
getCommandDocument
(
$server
);
}
}
}
}
src/Operation/FindOneAndReplace.php
View file @
1eebfe0d
...
@@ -149,8 +149,8 @@ class FindOneAndReplace implements Executable, Explainable
...
@@ -149,8 +149,8 @@ class FindOneAndReplace implements Executable, Explainable
return
$this
->
findAndModify
->
execute
(
$server
);
return
$this
->
findAndModify
->
execute
(
$server
);
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
findAndModify
->
getCommandDocument
();
return
$this
->
findAndModify
->
getCommandDocument
(
$server
);
}
}
}
}
src/Operation/FindOneAndUpdate.php
View file @
1eebfe0d
...
@@ -152,8 +152,8 @@ class FindOneAndUpdate implements Executable, Explainable
...
@@ -152,8 +152,8 @@ class FindOneAndUpdate implements Executable, Explainable
return
$this
->
findAndModify
->
execute
(
$server
);
return
$this
->
findAndModify
->
execute
(
$server
);
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
return
$this
->
findAndModify
->
getCommandDocument
();
return
$this
->
findAndModify
->
getCommandDocument
(
$server
);
}
}
}
}
src/Operation/Update.php
View file @
1eebfe0d
...
@@ -181,7 +181,7 @@ class Update implements Executable, Explainable
...
@@ -181,7 +181,7 @@ class Update implements Executable, Explainable
return
new
UpdateResult
(
$writeResult
);
return
new
UpdateResult
(
$writeResult
);
}
}
public
function
getCommandDocument
()
public
function
getCommandDocument
(
Server
$server
)
{
{
$cmd
=
[
'update'
=>
$this
->
collectionName
,
'updates'
=>
[[
'q'
=>
$this
->
filter
,
'u'
=>
$this
->
update
]
+
$this
->
createUpdateOptions
()]];
$cmd
=
[
'update'
=>
$this
->
collectionName
,
'updates'
=>
[[
'q'
=>
$this
->
filter
,
'u'
=>
$this
->
update
]
+
$this
->
createUpdateOptions
()]];
...
...
src/Operation/UpdateMany.php
View file @
1eebfe0d
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
* @see \MongoDB\Collection::updateMany()
* @see \MongoDB\Collection::updateMany()
* @see http://docs.mongodb.org/manual/reference/command/update/
* @see http://docs.mongodb.org/manual/reference/command/update/
*/
*/
class
UpdateMany
implements
Executable
class
UpdateMany
implements
Executable
,
Explainable
{
{
private
$update
;
private
$update
;
...
@@ -104,4 +104,9 @@ class UpdateMany implements Executable
...
@@ -104,4 +104,9 @@ class UpdateMany implements Executable
{
{
return
$this
->
update
->
execute
(
$server
);
return
$this
->
update
->
execute
(
$server
);
}
}
public
function
getCommandDocument
(
Server
$server
)
{
return
$this
->
update
->
getCommandDocument
(
$server
);
}
}
}
src/Operation/UpdateOne.php
View file @
1eebfe0d
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
...
@@ -30,7 +30,7 @@ use MongoDB\Exception\UnsupportedException;
* @see \MongoDB\Collection::updateOne()
* @see \MongoDB\Collection::updateOne()
* @see http://docs.mongodb.org/manual/reference/command/update/
* @see http://docs.mongodb.org/manual/reference/command/update/
*/
*/
class
UpdateOne
implements
Executable
class
UpdateOne
implements
Executable
,
Explainable
{
{
private
$update
;
private
$update
;
...
@@ -104,4 +104,9 @@ class UpdateOne implements Executable
...
@@ -104,4 +104,9 @@ class UpdateOne implements Executable
{
{
return
$this
->
update
->
execute
(
$server
);
return
$this
->
update
->
execute
(
$server
);
}
}
public
function
getCommandDocument
(
Server
$server
)
{
return
$this
->
update
->
getCommandDocument
(
$server
);
}
}
}
tests/Operation/ExplainFunctionalTest.php
View file @
1eebfe0d
...
@@ -8,6 +8,8 @@ use MongoDB\Operation\Count;
...
@@ -8,6 +8,8 @@ use MongoDB\Operation\Count;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\Distinct
;
use
MongoDB\Operation\Distinct
;
use
MongoDB\Operation\Delete
;
use
MongoDB\Operation\Delete
;
use
MongoDB\Operation\DeleteMany
;
use
MongoDB\Operation\DeleteOne
;
use
MongoDB\Operation\Explain
;
use
MongoDB\Operation\Explain
;
use
MongoDB\Operation\Find
;
use
MongoDB\Operation\Find
;
use
MongoDB\Operation\FindAndModify
;
use
MongoDB\Operation\FindAndModify
;
...
@@ -16,6 +18,8 @@ use MongoDB\Operation\FindOneAndDelete;
...
@@ -16,6 +18,8 @@ use MongoDB\Operation\FindOneAndDelete;
use
MongoDB\Operation\FindOneAndReplace
;
use
MongoDB\Operation\FindOneAndReplace
;
use
MongoDB\Operation\FindOneAndUpdate
;
use
MongoDB\Operation\FindOneAndUpdate
;
use
MongoDB\Operation\Update
;
use
MongoDB\Operation\Update
;
use
MongoDB\Operation\UpdateMany
;
use
MongoDB\Operation\UpdateOne
;
use
MongoDB\Tests\CommandObserver
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
use
stdClass
;
...
@@ -49,8 +53,6 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -49,8 +53,6 @@ class ExplainFunctionalTest extends FunctionalTestCase
*/
*/
public
function
testDelete
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
public
function
testDelete
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
{
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$this
->
createFixtures
(
3
);
$this
->
createFixtures
(
3
);
$filter
=
[
'_id'
=>
1
];
$filter
=
[
'_id'
=>
1
];
...
@@ -63,6 +65,40 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -63,6 +65,40 @@ class ExplainFunctionalTest extends FunctionalTestCase
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
}
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testDeleteMany
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$this
->
createFixtures
(
3
);
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]];
$operation
=
new
DeleteMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testDeleteOne
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$this
->
createFixtures
(
3
);
$filter
=
[
'_id'
=>
1
];
$operation
=
new
DeleteOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
/**
/**
* @dataProvider provideVerbosityInformation
* @dataProvider provideVerbosityInformation
*/
*/
...
@@ -262,6 +298,42 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -262,6 +298,42 @@ class ExplainFunctionalTest extends FunctionalTestCase
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
}
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testUpdateMany
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$this
->
createFixtures
(
3
);
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]];
$update
=
[
'$inc'
=>
[
'x'
=>
1
]];
$operation
=
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
$update
);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testUpdateOne
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$this
->
createFixtures
(
3
);
$filter
=
[
'_id'
=>
[
'$lte'
=>
1
]];
$update
=
[
'$inc'
=>
[
'x'
=>
1
]];
$operation
=
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
$update
);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
public
function
provideVerbosityInformation
()
public
function
provideVerbosityInformation
()
{
{
return
[
return
[
...
...
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