我想使用合并MongoDB\Driver\Query and MongoDB\Driver\Command
。但它不起作用。谁能帮我。谢谢!
$filter = ['column1' => ['$ne' =>'abc']];
$options = [
'limit' => 1000,
/* Only return the following fields in the matching documents */
'projection' => [
'column2' => 1,
'column3' => 1,
'column4' => 1,
],
/* Return the documents in descending order of views */
'sort' => [
'created_date' => -1
],
];
$query = new MongoDB\Driver\Query($filter, $options);
$cmd = new MongoDB\Driver\Command([
// build the 'distinct' command
'distinct' => 'collection', // specify the collection name
'key' => 'column5', // specify the field for which we want to get the distinct values
'query' => $query // criteria to filter documents,
]);
$cursor = $mgClient->executeCommand('mydb', $cmd); // retrieve the results
$arr = current($cursor->toArray())->values; // get the distinct values as