I have a mongo query to get data from a mongo data base.
db.testDB.distinct("header.app", {"tags": {$exists: true, $in:["Release"]}});
Iam using this to fetch some data from mongo db.
But i need to use this query in php.
As an new to php am not aware of php mongo queries.
How can i convert this to php query
Sample conversion to PHP:
$query = ['tags' => ['$exists' => 1, '$in' => ['Release']]]; // your typical MongoDB query
$cmd = new MongoDB\Driver\Command([
// build the 'distinct' command
'distinct' => 'testDB', // specify the collection name
'key' => 'tags', // specify the field for which we want to get the distinct values
'query' => $query // criteria to filter documents
]);
$cursor = $manager->executeCommand('databasename', $cmd); // retrieve the results
Used with PHP Version 5.6.3, mongodb driver 1.2.9, MongoDB 3.4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With