Bug #74848 [Opn->Nab]: the parameter fields does not work
| From: | cmb@php.net | Date: | Thu, 07 Oct 2021 11:10:45 +0000 |
| Subject: | Bug #74848 [Opn->Nab]: the parameter fields does not work | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-17442@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74848&edit=1
ID: 74848
Updated by: cmb@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