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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: box at boxoft dot net
New email:
PHP Version: OS:

 

 [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: Fri Mar 29 13:01:29 2024 UTC