2
我遇到了麻煩試圖從集合獲取小時,減去3小時(GMT-3)
,如果我跑
db.post.aggregate(
[{$match : {'uri' : /fantastic/ } },
{
$project:
{
_id: 0,
created_at : 1,
date_minus_3 : {$subtract:["$created_at",3*60*60*1000]},
hour_from_original: { $hour: "$created_at" }
}
}
]
)
我得到
(...)
{
"created_at" : ISODate("2014-06-03T02:51:42.000Z"),
"date_minus_3" : ISODate("2014-06-02T23:51:42.000Z"),
"hour_from_original" : 2
},
(...)
,但如果我有什麼從 「date_minus_3」
db.post.aggregate(
[{$match : {'uri' : /fantastic/ } },
{
$project:
{
_id: 0,
created_at : 1,
date_minus_3 : {$subtract:["$created_at",3*60*60*1000]},
hour_from_original: { $hour: "$created_at" },
hour_from_date_minus_3 : {$hour: {$subtract:["$created_at",3*60*60*1000]}}
}
}
]
)
拿到小時
我得到一個錯誤信息
Error("Printing Stack Trace")@:0
()@src/mongo/shell/utils.js:37
([object Array])@src/mongo/shell/collection.js:866
@(shell):10
uncaught exception: aggregate failed: {
"errmsg" : "exception: the $hour operator does not accept an object as an operand",
"code" : 16021,
"ok" : 0
}
誰能幫助我?
它工作正常對於我來說MongoDB 3.0.2。你使用什麼版本? – JohnnyHK
db.version() 2.4.6 –