2017-04-02 18 views
0

ドライバのバージョンにより、現在mongodbとphpに関して多くの競合する投稿があります。私はドライバ1.2.7、PHP 5.6と 最新のMongodb検索コレクション

XAMPP

の最新のMongoDBを使用しています。これは、私の現在のコードです:

$filter = [ 'userID' => $myUserId, 'isSold' => true]; 

    $cmdOne = new MongoDB\Driver\Command([ 

     'distinct' => 'collectionNameHere', 
     'key' => 'productID', 
     'query' => $filter 

    ]); 

    $cursorOne = $connection->executeCommand('DatabaseNameHere', $cmdOne); 

    $products = current($cursorOne->toArray())->values; 

が非明確な結果を見つける方法はありますか?

これは、異なるMongoDBのドライバに動作しません: MongoDB search in collection

答えて

1

あなたはクエリフィルタと突起がexecuteQueryを使用するようにしました

$filter = [ 'userID' => $myUserId, 'isSold' => true]; 

$projection = ['projection' => ['productID' => 1]]; 

$query = new MongoDB\Driver\Query($filter, $projection); 

$cursor = $connection->executeQuery('DatabaseNameHere.CollectionNameHere', $query); 
+0

あなたは二行目をしてください説明できますか? - 主に1が表すもの – Gabrielus

+0

1/true出力にproductIDを含める。 0 /除外するfalse。より多くのプロジェクションルールはこちらhttps://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/ – Veeram

関連する問題