Aggregation in find query is not working while using aggregate method on collection do

StackOverflow https://stackoverflow.com/questions/23338310

  •  10-07-2023
  •  | 
  •  

質問

Works and returns me one record

db.gfk_products.aggregate([
    {$match : {product_id : '50910288'}},
    {$project : {
        features: "$features.key"
    }}
])

Does not return anything

db.gfk_products.find({

    aggregate : [
        {$match : {product_id : '50910288'}},
        {$project : {
            features: "$features.key"
        }}
    ]
})

Don't know why! Second query is generated by mongodb adapter for cakephp.

EDIT

Respective Cakephp Code

$cond['conditions'] = array(
    'aggregate' => array(
        array(
            '$match' => array(
                'product_id' => $itemID
            ),
        ),
        array(
            '$project' => array(
                'features' => '$features.key'
            ),
        ),
    ),
);
$result = $this->Product->find('all',$cond);
役に立ちましたか?

解決

Ankit,

There is no facility in MongoDB to execute aggregate pipeline via the find query. You can find more details about the method used specifically for aggregate in MongoDB/PHP driver - http://www.php.net/manual/en/mongocollection.aggregate.php .

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top