2017-08-29 147 views
0

我有一個mongo查詢來從mongo數據庫中獲取數據。PHP mongo查詢從數據庫獲取不同的數據

db.testDB.distinct("header.app", {"tags": {$exists: true, $in:["Release"]}}); 

Iam使用它從mongo db中獲取一些數據。

但我需要在php.

使用該查詢作爲一個新的PHP我不知道PHP蒙戈查詢。

我怎樣才能將它轉換爲PHP查詢

回答

1

採樣轉換到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