'php mongodb find syntax issue
I am trying to find the correct syntax for the find command. I have been using the following syntax for a while and it works.
$client = new MongoDB\Client("mongodb://localhost");
$dbs = $client ->dbX->main;
$ result = $dbs -> find ([]);
foreach($result as $main_entry) {
}
But when I try to modify the find() to only get the records where client is ABC, I get syntax errors. Unexpected {, expecting ]. I tried many variations but I cannot seem to find the correct syntax to make it work.
$ result = $dbs -> find ([ { "client" : "ABC" } ]);
Can someone please tell me what the correct syntax of brackets is so I can get this seemingly simple find to work? Thank you.
Solution 1:[1]
Basic find in php:
$result = $dbs->find(array('client' => 'ABC'));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | R2D2 |
