【发布时间】:2016-12-07 05:53:28
【问题描述】:
我有一个聚合脚本,它在最后阶段产生以下输出。我现在想按帐户类别进行分组和汇总,但它告诉我我正试图从 BSON 类型 EOO 转换为 Date - 我在任何地方的代码中都看不到。
{
"_id" : {
"party_uuid" : "phildominickcompany",
"connection_uuid" : "5738fc661a21db15b5c45b49",
"account_balances_date" : ISODate("2016-06-30T10:00:00.000+0000"),
"object_origin_category" : "Bookkeeping",
"object_origin" : "Sage One"
},
"account_identifier" : "5010",
"account_name" : "Cost of sales - materials",
"account_category" : "Sales Expense",
"account_type" : null,
"account_value_type" : "debit",
"account_value" : NumberInt(0)
}
{
"_id" : {
"party_uuid" : "phildominickcompany",
"connection_uuid" : "5738fc661a21db15b5c45b49",
"account_balances_date" : ISODate("2016-07-31T10:00:00.000+0000"),
"object_origin_category" : "Bookkeeping",
"object_origin" : "Sage One"
},
"account_identifier" : "4000",
"account_name" : "Sales Type A",
"account_category" : "Sales Revenue",
"account_type" : null,
"account_value_type" : "credit",
"account_value" : 57728.33
}
{
"_id" : {
"party_uuid" : "phildominickcompany",
"connection_uuid" : "5738fc661a21db15b5c45b49",
"account_balances_date" : ISODate("2016-07-31T10:00:00.000+0000"),
"object_origin_category" : "Bookkeeping",
"object_origin" : "Sage One"
},
"account_identifier" : "5000",
"account_name" : "Cost of sales - goods",
"account_category" : "Sales Expense",
"account_type" : null,
"account_value_type" : "debit",
"account_value" : NumberInt(10000)
}
{
"_id" : {
"party_uuid" : "phildominickcompany",
"connection_uuid" : "5738fc661a21db15b5c45b49",
"account_balances_date" : ISODate("2016-07-31T10:00:00.000+0000"),
"object_origin_category" : "Bookkeeping",
"object_origin" : "Sage One"
},
"account_identifier" : "5010",
"account_name" : "Cost of sales - materials",
"account_category" : "Sales Expense",
"account_type" : null,
"account_value_type" : "debit",
"account_value" : NumberInt(20000)
}
{
"_id" : {
"party_uuid" : "phildominickcompany",
"connection_uuid" : "5738fc661a21db15b5c45b49",
"account_balances_date" : ISODate("2016-07-31T10:00:00.000+0000"),
"object_origin_category" : "Bookkeeping",
"object_origin" : "Sage One"
},
"account_identifier" : "6200",
"account_name" : "Marketing",
"account_category" : "Other Expense",
"account_type" : null,
"account_value_type" : "debit",
"account_value" : NumberInt(1500)
}
我现在尝试申请的阶段如下。它应该按年和月对account_value 求和。它产生了一个错误,告诉我我正在尝试从 EOO 转到约会。
$group : {
_id: {"party_uuid" : "$party_uuid",
"account_category" : "$account_category",
"account_balances_year" : {$year : "$account_balances_date"},
"account_balances_month" : {$month : "$account_balances_date"},
"account_category" : "$account_category",
"account_type" : "$account_type",
"object_origin_category" : "$object_origin_category",
"object_origin" : "$object_origin"},
"month_value" : { $sum: "$account_value"}
}
谢谢,马特
【问题讨论】:
-
你好,马特,你能发布你的 JSON。
标签: mongodb mongodb-query aggregation-framework