|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63333 PHP should return documents as objects, not arrays.
Submitted: 2012-10-22 15:00 UTC Modified: 2012-11-29 16:20 UTC
From: dtrenz at gmail dot com Assigned:
Status: Wont fix Package: mongo (PECL)
PHP Version: 5.3.18 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-10-22 15:00 UTC] dtrenz at gmail dot com
When querying as MongoDB collection, the Mongo PHP module returns document 
objects as arrays, not as objects.

Mongo is comprised of collections of BSON objects, which should be stored & 
retrieved as objects, not as arrays.

Even the tutorial ( refers to 
these arrays as "objects" or "$obj", which is puzzling.

Test script:

$m = new Mongo();

$collection = $m->test->users;

$collection->insert(array('name' => 'John Doe'));

$cursor = $m->test->users->findOne();



Expected result:
stdClass Object
    [_id] => MongoId Object
            [$id] => 50818a58d0d2ac397739d963

    [name] => John Doe

Actual result:
    [_id] => MongoId Object
            [$id] => 50818a58d0d2ac397739d963

    [name] => John Doe


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-29 16:20 UTC]
Automatic comment from SVN on behalf of derick
Log: Bug #63333: %s/$obj/$document
 [2012-11-29 16:20 UTC]
-Status: Open +Status: Wont fix
 [2012-11-29 16:20 UTC]
We can't ever change this. It would break all scripts reading data from MongoDB here. I have change the tutorial to use $document instead of $obj though (which will show up when the docs get rebuild next).
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 07:01:29 2024 UTC