Doc #75364 [Fbk->Nab]: undefined method MongoDB\Collection::group()
| From: | derick@php.net | Date: | Thu, 12 Oct 2017 11:45:49 +0000 |
| Subject: | Doc #75364 [Fbk->Nab]: undefined method MongoDB\Collection::group() | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15073@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75364&edit=1
ID: 75364
Updated by: derick@php.net
Reported by: a dot pendinelli92 at gmail dot com
Summary: undefined method MongoDB\Collection::group()
-Status: Feedback
+Status: Not a bug
Type: Documentation Problem
Package: Unknown/Other Function
Operating System: Windows 8.1
PHP Version: 7.1.10
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Hi,
there is no group() method. What you probably should do, is an aggregation() with a $group as
pipeline argument. Something like:
$g = $collection->aggregate( [
[ '$group' => [ '_id' => '$id', 'items' => [
'$push' => '$name'] ] ]
] );
But as this is not a bug, neither in code or documented, I have closed this ticket. If you have
further questions, feel free to ask at https://groups.google.com/forum/#!forum/mongodb-user
or on IRC at Freenode/#mongoDB
cheers,
Derick
Previous Comments:
------------------------------------------------------------------------
[2017-10-12 11:31:33] requinix@php.net
The only MongoDB\Collection I can find is at
https://github.com/mongodb/mongo-php-library
which we don't manage, and their docs
https://docs.mongodb.com/php-library/current/reference/class/MongoDBCollection/
don't mention a group() method.
------------------------------------------------------------------------
[2017-10-12 11:20:12] a dot pendinelli92 at gmail dot com
Description:
------------
While trying to use group() function for MongoDB
Fatal error: Uncaught Error: Call to undefined method MongoDB\Collection::group()
Test script:
---------------
<?php
require 'C:/xampp/php/vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->mongo_Test->users;
$keys = array("id" => 1);
$initial = array("items" => array());
$reduce = "function (obj, prev) { prev.items.push(obj.name); }";
//not working
$g = $collection->group($keys, $initial, $reduce);
var_dump($g);
?>
Actual result:
--------------
Fatal error: Uncaught Error: Call to undefined method MongoDB\Collection::group()
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75364&edit=1