我正在努力想出一件似乎无法理解的事情。如果下面列出的transaction_date (顺便说一句,它是一个字符串,我似乎无法让它转换成ISODate以换取爱情或金钱)是在UTC时间,那么我如何查询一个月的范围(如果是一个日期)并对销售进行汇总?
我不想要一个UTC月,我要本地时区月。我想我的问题是双重的,
谢谢,马特
{
"_id" : ObjectId("5ab485c669150d532c41769f"),
"object_origin" : "vend",
"company" : "5a9a73bb-0c5a-41db-8d06-76ac2d1e04b0",
"connection" : "2f758916-2eb1-4d95-a3bb-7d6258bc2143",
"object_creation_date" : ISODate("2018-03-16T10:40:20.875+13:00"),
"transaction_date" : "2018-03-07T11:36:48",
"transaction_gross_value" : 165,
"transaction_net_value" : 137.5,
"transaction_tax_value" : 27.5,
"transaction_cost_value" : 80,
"object_class" : "goods-service-transaction",
"object_origin_category" : "point-of-sale",
"object_type" : "receipt",
"object_origin_type" : "offline",
"transaction_reference" : "119",
"transaction_status" : "CLOSED",
"transaction_currency" : "GBP",
"party_identifier" : "WALKIN",
"staff_identifier" : "02dcd191-ae2b-11e6-f485-79681a952bd4",
"staff_name" : "uat2@9spokes.com",
"line_items" : [
{
"item_name" : "Dress Shirt / Polyester / Large",
"item_system_id" : "5051599d-40c2-a66a-11e8-21fbce105df0",
"item_identifier" : "10024",
"item_category" : "sales-revenue",
"item_quantity" : 1,
"item_net_unit_sale_value" : 62.5,
"item_net_unit_discount_value" : 0,
"item_net_unit_member_value" : 0,
"item_net_unit_cost_value" : 60,
"item_unit_tax_value" : 12.5,
"item_price_list_reference" : 0,
"item_total_sale_value" : 62.5,
"item_total_tax_value" : 12.5
},
{
"item_name" : "Dress Shirt / Cotton / Large",
"item_system_id" : "5051599d-40c2-a66a-11e8-21fbd07bb8a4",
"item_identifier" : "10021",
"item_category" : "sales-revenue",
"item_quantity" : 1,
"item_net_unit_sale_value" : 75,
"item_net_unit_discount_value" : 0,
"item_net_unit_member_value" : 0,
"item_net_unit_cost_value" : 20,
"item_unit_tax_value" : 15,
"item_price_list_reference" : 0,
"item_total_sale_value" : 75,
"item_total_tax_value" : 15
}
]
}
发布于 2018-03-26 07:13:26
使用$dateFromString
3.6,您可以使用MongoDB并设置一个时区。这将返回一个可以使用$gt
或$lt
:查询的ISODate()
。
db.collection.aggregate([{
"$project": {
"transaction_date": {
"$dateFromString": {
"dateString": "$transaction_date",
"timezone": "America/New_York"
}
}
}
}])
这个会回来的
{
"_id": ObjectId("5ab485c669150d532c41769f"),
"transaction_date": ISODate("2018-03-07T16:36:48Z")
}
https://stackoverflow.com/questions/49473382
复制相似问题