MongoDB I want to group statistical arrays, and then the condition is the time region, how to achieve

I want to group statistical arrays, and then the condition is the time region, how to achieve

// 
// [Error] A pipeline stage specification object must contain exactly one field. at line 1, column 1
db.getCollection("user_reg").aggregate([
    {
        "$group": {
            _id: "$isfrom",
            count: {
                "$sum": 1
            },
        },
        "$match": {
            "regtime": {
                "$gte": "2000-01-01",
                "$lte": "2020-01-01"
            }
        }
    }
]) 
May.26,2022

I don't know what the raw data looks like, but generally speaking, you should filter before grouping. At the same time, there should be only one operator ($match/$group, etc.) in an array element:

db.getCollection("user_reg").aggregate([
    {
        "$match": {
            "regtime": {
                "$gte": '2000-01-01',
                "$lte": '2020-01-01'
            }
        }
    },
    {
        "$group": {
            _id: "$isfrom",
            count: {
                "$sum": 1
            },
        }
    }
])
Menu