您可以使用
$unwind将
event数组字段“转换”
为单个嵌入式文档,然后
$replaceRoot将该
event字段“提升”
为新的“根”:
pipe := session.DB(shared.DatabaseNamespace).C(dao.collection).Pipe([]bson.M{ { "$match": bson.M{ "is_published": true, // Boost is active "start_date": bson.M{"$lt": now}, // now is between start and end "end_date": bson.M{"$gt": now}, // now is between start and end }, }, { "$lookup": bson.M{ "from": "events", "localField": "_event_id", "foreignField": "_id", "as":"event", }, }, {"$unwind": "$event"}, {"$replaceRoot": bson.M{ "newRoot": "$event" }},})
如果给定存在多个事件,则此解决方案将正确处理
EventBoost。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)