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
eaaf42b5
Commit
eaaf42b5
authored
Dec 05, 2014
by
Hannes Magnusson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHP-1301: Collection::aggregate()
parent
db99d16a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
write.php
examples/write.php
+4
-0
Collection.php
src/MongoDB/Collection.php
+65
-0
No files found.
examples/write.php
View file @
eaaf42b5
...
...
@@ -62,6 +62,10 @@ try {
echo
"Distinct countries:
\n
"
;
var_dump
(
$result
);
$aggregate
=
$collection
->
aggregate
(
array
(
array
(
'$project'
=>
array
(
"name"
=>
1
,
"_id"
=>
0
))),
array
(
"useCursor"
=>
false
));
printf
(
"Should be 3 different people
\n
"
);
var_dump
(
$aggregate
);
$result
=
$collection
->
updateMany
(
array
(
"citizen"
=>
"Iceland"
),
array
(
'$set'
=>
array
(
"viking"
=>
true
))
...
...
src/MongoDB/Collection.php
View file @
eaaf42b5
...
...
@@ -288,6 +288,71 @@ class Collection {
);
}
/* }}} */
function
aggregate
(
array
$pipeline
,
array
$options
=
array
())
{
/* {{{ */
$options
=
array_merge
(
$this
->
getAggregateOptions
(),
$options
);
$options
=
$this
->
_massageAggregateOptions
(
$options
);
$cmd
=
array
(
"aggregate"
=>
$this
->
collname
,
"pipeline"
=>
$pipeline
,
)
+
$options
;
$doc
=
$this
->
_runCommand
(
$this
->
dbname
,
$cmd
)
->
getResponseDocument
();
if
(
$doc
[
"ok"
])
{
return
$doc
[
"result"
];
}
throw
$this
->
_generateCommandException
(
$doc
);
}
/* }}} */
function
getAggregateOptions
()
{
/* {{{ */
$opts
=
array
(
/**
* Enables writing to temporary files. When set to true, aggregation stages
* can write data to the _tmp subdirectory in the dbPath directory. The
* default is false.
*
* @see http://docs.mongodb.org/manual/reference/command/aggregate/
*/
"allowDiskUse"
=>
false
,
/**
* The number of documents to return per batch.
*
* @see http://docs.mongodb.org/manual/reference/command/aggregate/
*/
"batchSize"
=>
0
,
/**
* The maximum amount of time to allow the query to run.
*
* @see http://docs.mongodb.org/manual/reference/command/aggregate/
*/
"maxTimeMS"
=>
0
,
/**
* Indicates if the results should be provided as a cursor.
*
* The default for this value depends on the version of the server.
* - Servers >= 2.6 will use a default of true.
* - Servers < 2.6 will use a default of false.
*
* As with any other property, this value can be changed.
*
* @see http://docs.mongodb.org/manual/reference/command/aggregate/
*/
"useCursor"
=>
true
,
);
/* FIXME: Add a version check for useCursor */
return
$opts
;
}
/* }}} */
protected
function
_massageAggregateOptions
(
$options
)
{
if
(
$options
[
"useCursor"
])
{
$options
[
"cursor"
]
=
array
(
"batchSize"
=>
$options
[
"batchSize"
]);
}
unset
(
$options
[
"useCursor"
],
$options
[
"batchSize"
]);
return
$options
;
}
protected
function
_generateCommandException
(
$doc
)
{
/* {{{ */
if
(
$doc
[
"errmsg"
])
{
return
new
Exception
(
$doc
[
"errmsg"
]);
...
...
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