1
我正在使用MongoDB 3.4.9,並且想要每月報告w.r.t.客戶信息,這裏有樣品例如MongoDB的記錄與收到的嵌套項目和錯誤是:無法從BSON類型字符串轉換爲聚合管道上的日期
不能從BSON類型的字符串轉換爲Date
{
"_id" : ObjectId("59da6a331c7a9ac0b6674fe8"),
"date" : ISODate("2017-10-08T18:10:59.899Z"),
"items" : [
{
"quantity" : 1,
"price" : 47.11,
"desc" : "Item #1"
},
{
"quantity" : 2,
"price" : 42.0,
"desc" : "Item #2"
}
],
"custInfo" : "Tobias Trelle, gold customer"
}
{
"_id" : ObjectId("59da6a511c7a9ac0b6674fed"),
"date" : ISODate("2017-10-08T18:11:28.961Z"),
"items" : [
{
"quantity" : 1,
"price" : 47.11,
"desc" : "Item #1"
},
{
"quantity" : 2,
"price" : 42.0,
"desc" : "Item #2"
}
],
"custInfo" : "Tobias Trelle, gold customer"
}
{
"_id" : ObjectId("59da6a511c7a9ac0b6674ff0"),
"date" : ISODate("2017-10-08T18:11:29.133Z"),
"items" : [
{
"quantity" : 1,
"price" : 47.11,
"desc" : "Item #1"
},
{
"quantity" : 2,
"price" : 42.0,
"desc" : "Item #2"
}
],
"custInfo" : "Tobias Trelle, gold customer"
}
這裏是MongoDB的查詢計算總和custInfo
month明智
db.runCommand({aggregate:"order", pipeline :
[{$match : {$and : [{"date" : {$gte : ISODate("2016-10-08T18:10:59.899Z")}},
{"date" : {$lte : ISODate("2018-10-08T18:10:59.899Z")}}]}}
,
{ "$project" : { "custInfo" : 1 ,"count" : 1 , "date" : 1 ,
"duration" : {"$month" : [ "date"]}}},
{ "$group" : { "_id" :
{ "duration" : "$duration" , "custInfo" : "$custInfo"} ,"count" : { "$sum" : 1} }}
]}//,
//cursor:{batchSize:1000}
)
請幫助我哪裏錯了。
問候 克里斯