Edit report at https://bugs.php.net/bug.php?id=74848&edit=1

 ID:                 74848
 Updated by:         c...@php.net
 Reported by:        blackpanther dot online at gmx dot de
 Summary:            the parameter fields does not work
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            mongodb
 PHP Version:        7.1.6
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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>


Previous Comments:
------------------------------------------------------------------------
[2017-07-03 14:09:15] 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
        )

)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74848&edit=1

-- 
PECL development discussion Mailing List (https://pecl.php.net/)
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to