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
08d83140
Commit
08d83140
authored
Jan 29, 2018
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-314: Make mapReduce inline check more robust
parent
da5fb0c3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
4 deletions
+28
-4
Collection.php
src/Collection.php
+28
-4
No files found.
src/Collection.php
View file @
08d83140
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
namespace
MongoDB
;
namespace
MongoDB
;
use
MongoDB\BSON\JavascriptInterface
;
use
MongoDB\BSON\JavascriptInterface
;
use
MongoDB\BSON\Serializable
;
use
MongoDB\ChangeStream
as
ChangeStreamResult
;
use
MongoDB\ChangeStream
as
ChangeStreamResult
;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Manager
;
...
@@ -830,7 +831,7 @@ class Collection
...
@@ -830,7 +831,7 @@ class Collection
*/
*/
public
function
mapReduce
(
JavascriptInterface
$map
,
JavascriptInterface
$reduce
,
$out
,
array
$options
=
[])
public
function
mapReduce
(
JavascriptInterface
$map
,
JavascriptInterface
$reduce
,
$out
,
array
$options
=
[])
{
{
$hasOutputCollection
=
!
$this
->
is
O
utInline
(
$out
);
$hasOutputCollection
=
!
$this
->
is
MapReduceOutp
utInline
(
$out
);
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
...
@@ -984,14 +985,37 @@ class Collection
...
@@ -984,14 +985,37 @@ class Collection
return
new
Collection
(
$this
->
manager
,
$this
->
databaseName
,
$this
->
collectionName
,
$options
);
return
new
Collection
(
$this
->
manager
,
$this
->
databaseName
,
$this
->
collectionName
,
$options
);
}
}
private
function
isOutInline
(
$out
)
/**
* Return whether the "out" option for a mapReduce operation is "inline".
*
* This is used to determine if a mapReduce command requires a primary.
*
* @see https://docs.mongodb.com/manual/reference/command/mapReduce/#output-inline
* @param string|array|object $out Output specification
* @return boolean
* @throws InvalidArgumentException
*/
private
function
isMapReduceOutputInline
(
$out
)
{
{
if
(
!
is_array
(
$out
)
&&
!
is_object
(
$out
))
{
if
(
!
is_array
(
$out
)
&&
!
is_object
(
$out
))
{
return
false
;
return
false
;
}
}
$out
=
(
array
)
$out
;
if
(
$out
instanceof
Serializable
)
{
$out
=
$out
->
bsonSerialize
();
}
if
(
is_object
(
$out
))
{
$out
=
get_object_vars
(
$out
);
}
if
(
!
is_array
(
$out
))
{
throw
InvalidArgumentException
::
invalidType
(
'$out'
,
$out
,
'array or object'
);
}
reset
(
$out
);
$firstKey
=
(
string
)
key
(
$out
);
return
key
(
$out
)
===
'inline'
;
return
$firstKey
===
'inline'
;
}
}
}
}
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