mongodb中具有_id的聚合的$match是一个对象
我查询了这个报表,得到了一些文件mongodb中具有_id的聚合的$match是一个对象,mongodb,Mongodb,我查询了这个报表,得到了一些文件 db.getCollection('myDocument').aggregate([ { $group: { _id: {"key1": "$key1", "key2": "$key2", "key3": "$key3"}, count: { $sum: 1 } } }, { $match: { count: { $g
db.getCollection('myDocument').aggregate([
{
$group: {
_id: {"key1": "$key1", "key2": "$key2", "key3": "$key3"},
count: { $sum: 1 }
}
},
{
$match: {
count: { $gte: 3 }
}
},
{ $sort : { count : -1} },
]);
然后,我添加了一个过滤器,用上面查询中找到的值缩小结果范围。但是没有文件
db.getCollection('test_driver1').aggregate([
{
$group: {
_id: {"key1": "$key1", "key2": "$key2", "key3": "$key3"},
count: { $sum: 1 }
}
},
{
$match: {
count: { $gte: 3 },
_id: {"key1": 1234} // <= 1234 is a found value. what wrong with this condition?
}
},
{ $sort : { count : -1} },
]);
db.getCollection('test_driver1')。聚合([
{
$group:{
_id:{“key1”:“$key1”,“key2”:“$key2”,“key3”:“$key3”},
计数:{$sum:1}
}
},
{
$match:{
计数:{$gte:3},
_id:{“key1”:1234}/我认为您试图实现的是在一个平台上进行匹配
请尝试以下操作:
db.getCollection('test_driver1').aggregate([
{
$group: {
_id: {"key1": "$key1", "key2": "$key2", "key3": "$key3"},
count: { $sum: 1 }
}
},
{
$match: {
count: { $gte: 3 },
"_id.key1": 1234
}
},
{ $sort : { count : -1} },
]);
使用“_id.key1”:1234thx anhlc。它有效。你能创建一个答案吗?然后,我会接受它