2013-12-17 83 views
0

我嘗試將mongo查詢轉換爲Doctrine。我是新的教條和PHP,我無法將我的查詢翻譯成教條。學說MongoDB querybuilder組

我已經被封鎖了兩天了!

我無法理解官方的引用

http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/query-builder-api.html

任何人都可以幫助我!

查詢是一個:

db.prices.group({ 
    key: { product: 1, category:1 }, 
cond: { product: "1" }, 
    reduce: function (curr, result) { 
     result.total += curr.amount; 
    }, 
    initial: { total : 0 } 
    }) 

的文件看起來像:

{ 
    "_id" : ObjectId("52af22231852fcf313b49375"), 
    "product" : DBRef("products", ObjectId("529d8db11852fc7a2ac182ac")), 
    "category" : "1", 
    "date" : ISODate("2013-12-16T15:54:11Z"), 
    "price" : 51 
} 

謝謝!!

回答

2

我找到了解決辦法,

$qm = $this->dm->createQueryBuilder ('\model\entity \Product')->group (array (
     'product' => 1 
), array (
     'total' => 0 
))->reduce ('function (curr, result) { result.total += curr.price;}'); 

$qm->field ('category')->equals ($idCategory); 

$result = $qm->getQuery()->execute();