我可以使用点符号聚合mongoDB中的嵌入文档吗?

我可以使用点符号聚合mongoDB中的嵌入文档吗?,mongodb,aggregation-framework,Mongodb,Aggregation Framework,我在MongoDb中有这样一个文档: { "_id" : ObjectId("56b88d5f2628a6bca1b17f99"), "first_name" : "JAMES", "last_name" : "SMITH", "accounts" : [ { "account_type" : "Savings",

我在MongoDb中有这样一个文档:

{
        "_id" : ObjectId("56b88d5f2628a6bca1b17f99"),
        "first_name" : "JAMES",
        "last_name" : "SMITH",
        "accounts" : [
                {
                        "account_type" : "Savings",
                        "account_balance" : 8995952.153640702,
                        "currency" : "PESO"
                },
                {
                        "account_type" : "Checking",
                        "account_balance" : 3901436.5580737568,
                        "currency" : "USD"
                }
        ]
}
我想按姓氏和账户进行分组。账户类型和每个相关余额的总和

我尝试这样的点表示法,但我有一个错误,我找不到这种聚合类型的解释:

db.bank_data.aggregate([ 
{$group:{_id: "$last_name",accounts.account_type:"$accounts.acount_type",
 total:{$sum:"$accounts.account_balance"}}}])

考虑首先在聚合管道中展开account字段,然后使用如下所选的属性进行分组

    db.bank_data.aggregate([
        {$unwind: '$accounts' },
        {$group: { _id: { last_name : "$last_name" , account_type: "$accounts.account_type" },
                  total:{$sum:"$accounts.account_balance"}
                 }
        }]);

考虑首先在聚合管道中展开account字段,然后使用如下所选的属性进行分组

    db.bank_data.aggregate([
        {$unwind: '$accounts' },
        {$group: { _id: { last_name : "$last_name" , account_type: "$accounts.account_type" },
                  total:{$sum:"$accounts.account_balance"}
                 }
        }]);