Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongodb中具有_id的聚合的$match是一个对象_Mongodb - Fatal编程技术网

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。它有效。你能创建一个答案吗?然后,我会接受它