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: -
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:
Status: Open Package: mongodb (PECL)
PHP Version: 7.1.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
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

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 26 17:03:37 2021 UTC