PHP mongo查询从数据库获取不同的数据
问题描述:
我有一个mongo查询来从mongo数据库中获取数据。PHP mongo查询从数据库获取不同的数据
db.testDB.distinct("header.app", {"tags": {$exists: true, $in:["Release"]}});
Iam使用它从mongo db中获取一些数据。
但我需要在php.
使用该查询作为一个新的PHP我不知道PHP蒙戈查询。
我怎样才能将它转换为PHP查询
答
采样转换到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
使用PHP版本5.6.3,MongoDB的驱动程序1.2.9,MongoDB的3.4