php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75364 undefined method MongoDB\Collection::group()
Submitted: 2017-10-12 11:20 UTC Modified: 2017-10-12 11:45 UTC
From: a dot pendinelli92 at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 7.1.10 OS: Windows 8.1
Private report: No CVE-ID: None
 [2017-10-12 11:20 UTC] 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()

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-12 11:31 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: mongodb +Package: Unknown/Other Function
 [2017-10-12 11:31 UTC] 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:45 UTC] derick@php.net
-Status: Feedback +Status: Not a bug
 [2017-10-12 11:45 UTC] derick@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 22:01:31 2024 UTC