我正在尝试使用mongo-odm重现以下工作查询 - 来自mongo控制台。
db.Record.aggregate([ {$match: {member: DBRef("Member", ObjectId("556e5dbfa10fdb0ddc0041c5"), "doctrine_odm")}}, {$sort: {timestamp: -1}}, {$group : {_id : "$details.type", firstRecord: {$first: "$_id"}}} ])
示例记录是
{
"_id" : ObjectId("556e5dbfa10fdb0ddc0041c8"),
"member" : DBRef("Member", ObjectId("556e5dbfa10fdb0ddc0041c5"), "doctrine_odm"),
"timestamp" : ISODate("2015-06-03T01:51:59Z"),
"details" : [
{
"accountNumber" : "101",
"type" : "premium"
}
]
}
我尝试了几种格式,最新的 - 仍然无效 - 就像这样
$collection = $dm->getDocumentCollection('Record');
$pipeline = array(
array(
'$match' => array(
"member" => \MongoDBRef::create("Member", "556e5dbfa10fdb0ddc0041c5", "doctrine_odm")
)
),
);
$results = $collection->aggregate($pipeline);
感谢。
答案 0 :(得分:0)
原来,ID需要是MongoId,所以如果我使用格式
$pipeline = array(
array(
'$match' => array(
"member" => \MongoDBRef::create("Member", new \MongoId("556e5dbfa10fdb0ddc0041c5"), "doctrine_odm")
)
),
);
有效。