本文介绍了$ replaceRoot在mongodb中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将聚合框架用于多个字段的分组依据
I use aggregation framework for group by of multiple fields as
{
_id:{_id:"$_id",feature_type:"$feature_type",feature_name:"$feature_name"},
features: { $push: "$features" }
}
给出类似
{_id:
{_id:1,feature_type:"Test",feature_name:"Tests"},
features:["23423","32423","2342342"]
}
但是我想要类似
{_id:1,feature_type:"Test",feature_name:"Tests",
features:["23423","32423","2342342"]
}
我如何使用聚集框架来实现这一目标.
how can i acheve this using aggregration framework.
推荐答案
db.collection.aggregate([
{
$project: {
_id: "$_id._id",
feature_type:"$_id.feature_type",
feature_name:"$_id.feature_name",
features:1
}
}
])
这篇关于$ replaceRoot在mongodb中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!