【发布时间】:2015-09-15 20:32:59
【问题描述】:
我的 mongo 数据库中有以下记录
> db.orders.find({});
{
"_id" : "WEB3",
"currency" : "USD",
"company" : "b",
"user_id" : "b",
"timestamp" : ISODate("2015-06-26T12:13:18.570Z"),
"details" : {
"ordered" : {
"total" : 1910.4,
"deliveryVAT" : 120,
"delivery" : 600,
"goodsVAT" : 198.4,
"goodsTotal" : 992
}
}
}
{
"_id" : "WEB1",
"currency" : "GBP",
"company" : "a",
"user_id" : "a",
"timestamp" : ISODate("2015-06-26T12:11:08.570Z"),
"details" : {
"ordered" : {
"total" : 1910.4,
"deliveryVAT" : 120,
"delivery" : 600,
"goodsVAT" : 198.4,
"goodsTotal" : 992
}
}
}
{
"_id" : "WEB2",
"currency" : "GBP",
"company" : "a",
"user_id" : "a",
"timestamp" : ISODate("2015-06-26T12:11:18.570Z"),
"details" : {
"ordered" : {
"total" : 1910.4,
"deliveryVAT" : 120,
"delivery" : 600,
"goodsVAT" : 198.4,
"goodsTotal" : 992
}
}
}
这里是插入语句:
db.orders.insert( { "_id" : "WEB1", "currency" : "GBP", "company" : "a", "user_id" : "a", "timestamp" : ISODate("2015-06-26T12:11:08.570Z"), "details" : { "ordered" : { "total" : 1910.4, "deliveryVAT" : 120, "delivery" : 600, "goodsVAT" : 198.4, "goodsTotal" : 992 } } });
db.orders.insert( { "_id" : "WEB2", "currency" : "GBP", "company" : "a", "user_id" : "a", "timestamp" : ISODate("2015-06-26T12:11:18.570Z"), "details" : { "ordered" : { "total" : 1910.4, "deliveryVAT" : 120, "delivery" : 600, "goodsVAT" : 198.4, "goodsTotal" : 992 } } });
db.orders.insert( { "_id" : "WEB3", "currency" : "USD", "company" : "b", "user_id" : "b", "timestamp" : ISODate("2015-06-26T12:13:18.570Z"), "details" : { "ordered" : { "total" : 1910.4, "deliveryVAT" : 120, "delivery" : 600, "goodsVAT" : 198.4, "goodsTotal" : 992 } } });
按日期分组然后按货币分组的正确方法是什么,这样我得到的结果类似于:
{ [ "date": "2015-06-26",
"currency": "USD",
"total": 1910.4,
"no_of_orders": 1],
[ "date": "2015-06-26",
"currency": "GBP",
"total": 3820.8,
"no_of_orders": 2]]
}
从以前的帖子mongodb sort result of aggregate query and display day name 我可以得到每天的订单数量,但是我不确定如何通过管道传输结果并按货币拆分,然后汇总结果?
非常感谢任何建议
【问题讨论】:
标签: mongodb