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
39fa0115
Commit
39fa0115
authored
Nov 15, 2018
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-398: Aggregate with $out should ignore batchSize option
parent
a452dd8b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
4 deletions
+39
-4
Aggregate.php
src/Operation/Aggregate.php
+7
-3
CrudSpecFunctionalTest.php
tests/Collection/CrudSpecFunctionalTest.php
+6
-1
AggregateFunctionalTest.php
tests/Operation/AggregateFunctionalTest.php
+26
-0
No files found.
src/Operation/Aggregate.php
View file @
39fa0115
...
...
@@ -255,7 +255,7 @@ class Aggregate implements Executable
$hasExplain
=
!
empty
(
$this
->
options
[
'explain'
]);
$hasOutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$this
->
pipeline
);
$command
=
$this
->
createCommand
(
$server
);
$command
=
$this
->
createCommand
(
$server
,
$hasOutStage
);
$options
=
$this
->
createOptions
(
$hasOutStage
,
$hasExplain
);
$cursor
=
(
$hasOutStage
&&
!
$hasExplain
)
...
...
@@ -287,9 +287,10 @@ class Aggregate implements Executable
* Create the aggregate command.
*
* @param Server $server
* @param boolean $hasOutStage
* @return Command
*/
private
function
createCommand
(
Server
$server
)
private
function
createCommand
(
Server
$server
,
$hasOutStage
)
{
$cmd
=
[
'aggregate'
=>
isset
(
$this
->
collectionName
)
?
$this
->
collectionName
:
1
,
...
...
@@ -325,7 +326,10 @@ class Aggregate implements Executable
}
if
(
$this
->
options
[
'useCursor'
])
{
$cmd
[
'cursor'
]
=
isset
(
$this
->
options
[
"batchSize"
])
/* Ignore batchSize if pipeline includes an $out stage, as no
* documents will be returned and sending a batchSize of zero could
* prevent the pipeline from executing at all. */
$cmd
[
'cursor'
]
=
isset
(
$this
->
options
[
"batchSize"
])
&&
!
$hasOutStage
?
[
'batchSize'
=>
$this
->
options
[
"batchSize"
]]
:
new
stdClass
;
}
...
...
tests/Collection/CrudSpecFunctionalTest.php
View file @
39fa0115
...
...
@@ -43,6 +43,11 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
$expectedData
=
isset
(
$test
[
'outcome'
][
'collection'
][
'data'
])
?
$test
[
'outcome'
][
'collection'
][
'data'
]
:
null
;
$this
->
initializeData
(
$initialData
,
$expectedData
);
if
(
isset
(
$test
[
'outcome'
][
'collection'
][
'name'
]))
{
$outputCollection
=
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$test
[
'outcome'
][
'collection'
][
'name'
]);
$outputCollection
->
drop
();
}
$result
=
null
;
$exception
=
null
;
...
...
@@ -81,7 +86,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
*/
private
function
assertEquivalentCollections
(
$expectedCollection
,
$actualCollection
)
{
$mi
=
new
MultipleIterator
;
$mi
=
new
MultipleIterator
(
MultipleIterator
::
MIT_NEED_ANY
)
;
$mi
->
attachIterator
(
new
IteratorIterator
(
$expectedCollection
->
find
()));
$mi
->
attachIterator
(
new
IteratorIterator
(
$actualCollection
->
find
()));
...
...
tests/Operation/AggregateFunctionalTest.php
View file @
39fa0115
...
...
@@ -2,6 +2,7 @@
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Collection
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
...
...
@@ -14,6 +15,28 @@ use stdClass;
class
AggregateFunctionalTest
extends
FunctionalTestCase
{
public
function
testBatchSizeIsIgnoredIfPipelineIncludesOutStage
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'$out'
=>
$this
->
getCollectionName
()
.
'.output'
]],
[
'batchSize'
=>
0
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertEquals
(
new
stdClass
,
$event
[
'started'
]
->
getCommand
()
->
cursor
);
}
);
$outCollection
=
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
()
.
'.output'
);
$outCollection
->
drop
();
}
public
function
testCurrentOpCommand
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
...
...
@@ -72,6 +95,9 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$event
[
'started'
]
->
getCommand
());
}
);
$outCollection
=
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
()
.
'.output'
);
$outCollection
->
drop
();
}
public
function
testEmptyPipelineReturnsAllDocuments
()
...
...
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