php mongodb find syntax issue - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, March 30, 2022

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.



source https://stackoverflow.com/questions/71667236/php-mongodb-find-syntax-issue

No comments:

Post a Comment