note 119142 added to class.mongodb-driver-query
| From: | maha88a | Date: | Sat, 09 Apr 2016 17:38:23 +0000 |
| Subject: | note 119142 added to class.mongodb-driver-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205189@lists.php.net to get a copy of this message | ||
Here is an example of Query to retrieve the records from MangoDB collection using a filter. It will
return in this case just one record that satisfy the filter id = 2.
Considering the following MangoDB collection:
<?php
/* my_collection */
/* 1 */
{
"_id" : ObjectId("5707f007639a94cbc600f282"),
"id" : 1,
"name" : "Name 1"
}
/* 2 */
{
"_id" : ObjectId("5707f0a8639a94f4cd2c84b1"),
"id" : 2,
"name" : "Name 2"
}
?>
I'm using the following code:
<?php
$filter = ['id' => 2];
$options = [
'projection' => ['_id' => 0],
];
$query = new MongoDB\Driver\Query($filter, $options);
$rows = $mongo->executeQuery('db_name.my_collection', $query); // $mongo contains the
connection object to MongoDB
foreach($rows as $r){
print_($r);
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 157.193.10.190
----
Manual Page -- http://php.net/manual/en/class.mongodb-driver-query.php
Edit -- https://master.php.net/note/edit/119142
Del: integrated -- https://master.php.net/note/delete/119142/integrated
Del: useless -- https://master.php.net/note/delete/119142/useless
Del: bad code -- https://master.php.net/note/delete/119142/bad+code
Del: spam -- https://master.php.net/note/delete/119142/spam
Del: non-english -- https://master.php.net/note/delete/119142/non-english
Del: in docs -- https://master.php.net/note/delete/119142/in+docs
Del: other reasons-- https://master.php.net/note/delete/119142
Reject -- https://master.php.net/note/reject/119142
Search -- https://master.php.net/manage/user-notes.php