我有這樣MongoDB中和文檔的集合 -如何將mongodb聚合中的毫秒數轉換爲日期?
[
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"amount": 2,
"balance": 0,
"txnTime": 1428907779206,
"txnSrc": "Dial_In",
"msisdn": "9789877667",
"circle": "Delhi",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"circle": "Delhi",
"amount": 2,
"balance": 0,
"txnTime": 1430111514796,
"txnSrc": "Dial_In",
"msisdn": "9189877667",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"circle": "Delhi",
"amount": 2,
"balance": 0,
"txnTime": 1430111514796,
"txnSrc": "Dial_In",
"msisdn": "9189877000",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 8,
"operatorId": 1,
"txnType": "DR",
"circle": "Delhi",
"amount": 2,
"balance": 0,
"txnTime": 1430111514796,
"txnSrc": "Dial_In",
"msisdn": "9189877010",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 8,
"operatorId": 1,
"txnType": "DR",
"circle": "Mumbai",
"amount": 2,
"balance": 0,
"txnTime": 1430111514796,
"txnSrc": "Dial_In",
"msisdn": "9180877010",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"circle": "Mumbai",
"amount": 2,
"balance": 0,
"txnTime": 1430111514796,
"txnSrc": "Dial_In",
"msisdn": "9180877010",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"circle": "Mumbai",
"amount": 2,
"balance": 0,
"txnTime": 1429986600000,
"txnSrc": "Dial_In",
"msisdn": "91808770101",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"circle": "Delhi",
"amount": 2,
"balance": 0,
"txnTime": 1429986600000,
"txnSrc": "Dial_In",
"msisdn": "91808070101",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"circle": "Delhi",
"amount": 2,
"balance": 0,
"txnTime": 1429986600000,
"txnSrc": "Dial_In",
"msisdn": "91808070101",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 8,
"operatorId": 1,
"txnType": "DR",
"circle": "Jaipur",
"amount": 2,
"balance": 0,
"txnTime": 1430111514796,
"txnSrc": "Dial_In",
"msisdn": "9180877010",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 8,
"operatorId": 1,
"txnType": "DR",
"circle": "UP-West",
"amount": 2,
"balance": 0,
"txnTime": 1430111514796,
"txnSrc": "Dial_In",
"msisdn": "9180877010",
"smsContent": "Hello Mr Arif"
},
{
"campaignId": 1,
"operatorId": 1,
"txnType": "DR",
"circle": "Delhi",
"amount": 2,
"balance": 0,
"txnTime": 1429986601111,
"txnSrc": "Dial_In",
"msisdn": "91808070101",
"smsContent": "Hello Mr Arif"
}
]
我爲組聚集查詢由該集合獨特的MSISDN的基礎上的日期,這是 -
db.campaign_wallet.aggregate({
"$match": {
"campaignId": 1,
"txnTime": {
"$gte": 1429554600000,
"$lte": 1430159400000
}
}
}, {
"$group": {
"_id": {
"txnTime": "$txnTime",
"msisdn": "$msisdn"
},
"msisdnCount": {
"$sum": 1
}
}
}, {
"$group": {
"_id": "$_id.txnTime",
"msisdns": {
"$push": {
"txnTime": "$_id.txnTime",
"count": "$msisdnCount"
},
},
"count": {
"$sum": "$msisdnCount"
}
}
});
-
這是毫秒級的MSISDN號碼給時間的基礎上,正確的結果我必須在查詢中將時間(毫秒)轉換爲日期,以便它將根據日期過濾數據,而不是精確的時間(以毫秒爲單位)。解決辦法是什麼?
我想你忘了提及你實際的問題是什麼。 – Philipp
@ Philipp我編輯的問題。我想在mongodb聚合查詢中更改時間毫秒。 –