php.net |  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
Votes:2
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 + 2 = ?
Subscribe to this entry?

 
 [2015-01-20 03:27 UTC] box at boxoft dot net
Description:
------------
---
From manual page: http://www.php.net/mongocollection.distinct
---

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

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

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

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

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

array(2) {
  [0]=>
  int(10010)
  [1]=>
  int(99701)
}

and 

array(2) {
  [0]=>
  int(25)
  [1]=>
  int(31)
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-03 16:58 UTC] jmikola@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: jmikola
 [2015-04-03 16:58 UTC] jmikola@php.net
Thanks for reporting this issue. Development for the "mongo" extension is primarily managed through our JIRA project, so I've opened https://jira.mongodb.org/browse/PHP-1427 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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 16:01:31 2024 UTC