php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74848 the parameter fields does not work
Submitted: 2017-07-03 14:09 UTC Modified: 2021-10-07 11:10 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: blackpanther dot online at gmx dot de Assigned: cmb (profile)
Status: Not a bug Package: mongodb (PECL)
PHP Version: 7.1.6 OS:
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: blackpanther dot online at gmx dot de
New email:
PHP Version: OS:

 

 [2017-07-03 14:09 UTC] blackpanther dot online at gmx dot de
Description:
------------
---
From manual page: http://www.php.net/mongocollection.find
---

If you pass the second parameter fields, you should receive only the fields given, but actually you receive all.

You can pass ["field_a" => true] and get all fields. The same then you pass ["field_a" => false].

So it's not working.
(If you check the mongodb's find method directly on the database without php by collection.find({},{"field_a":1}) it works properly)

Test script:
---------------
require '../vendor/autoload.php';

$mongodb = new MongoDB\Client("mongodb://xx:xx@localhost:27017/test"); // needs an existing mongodb server
$collection = $mongodb->test->phpfind; // needs an existing database

// create a new record
$collection->insertOne(['field_a' => 'A', 'field_b' => 'B']);

// should return a entry with only _id and field_a as fields
print_r($collection->findOne([], ['field_a' => true]));

// should return a entry with only _id and field_b as fields
print_r($collection->findOne([], ['field_a' => false]));

Expected result:
----------------
MongoDB\Model\BSONDocument Object
(
    [storage:ArrayObject:private] => Array
        (
            [_id] => MongoDB\BSON\ObjectID Object
                (
                    [oid] => 595a4cd3a1b69920b0003641
                )

            [field_a] => A
        )

)
MongoDB\Model\BSONDocument Object
(
    [storage:ArrayObject:private] => Array
        (
            [_id] => MongoDB\BSON\ObjectID Object
                (
                    [oid] => 595a4cd3a1b69920b0003641
                )

            [field_b] => B
        )

)

Actual result:
--------------
MongoDB\Model\BSONDocument Object
(
    [storage:ArrayObject:private] => Array
        (
            [_id] => MongoDB\BSON\ObjectID Object
                (
                    [oid] => 595a4cd3a1b69920b0003641
                )

            [field_a] => A
            [field_b] => B
        )

)
MongoDB\Model\BSONDocument Object
(
    [storage:ArrayObject:private] => Array
        (
            [_id] => MongoDB\BSON\ObjectID Object
                (
                    [oid] => 595a4cd3a1b69920b0003641
                )

            [field_a] => A
            [field_b] => B
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-07 11:10 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-10-07 11:10 UTC] cmb@php.net
It seems you've mixed up Mongo and MongoDB; the documentation of
the former is not necessarily valid for the latter, and in this
case this actually looks like an issue with the Mongo PHP library,
so please report there[1], if it still persists.

[1] <https://github.com/mongodb/mongo-php-library/issues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 05:01:30 2024 UTC