|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68858 MongoCollection::distinct("...", []) doesn't work for MongoDB 2.8
Submitted: 2015-01-20 03:27 UTC Modified: 2015-04-03 16:58 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: box at boxoft dot net Assigned: jmikola (profile)
Status: Closed Package: mongo (PECL)
PHP Version: 5.6.4 OS: Windows 7
Private report: No CVE-ID: None
 [2015-01-20 03:27 UTC] box at boxoft dot net
From manual page:

Let's add 2 lines to the 1st example like this:

$retval = $c->distinct("zip-code", array());

Let's add 2 lines to the 2nd example like this:

$retval = $c->distinct("user.points", array());

Let's run the 2 examples after running MongoDB 2.8 rc5 and we'll get 
instead of 

array(2) {


array(2) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-03 16:58 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: jmikola
 [2015-04-03 16:58 UTC]
Thanks for reporting this issue. Development for the "mongo" extension is primarily managed through our JIRA project, so I've opened to track this issue.

The error you were seeing was due to new validation in the 3.0+ server, which requires query documents to actually be BSON objects, while BSON arrays were previously allowed. As you may know, the driver converts PHP arrays to BSON objects or arrays based on whether they have sequential, numeric keys. As a result, an empty PHP array becomes a BSON array.

This will ultimately be fixed in the driver by ensuring the query parameter to distinct() is always serialized to a BSON object. As a work-around, you can either omit the empty array parameter or manually cast the parameter to a PHP object before calling distinct().
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Apr 10 23:01:24 2021 UTC