当我运行以下查询时,cant $subtract atimestamp from a timestamp
发生了。有没有其他方法可以减去两个时间戳或将时间戳转换为整数然后进行减法?
{
"collection": "visits_logs",
"aggregate": [
{
"$group": {
"_id": {
"_sid": "$_sid"
},
"first1": {
"$first": "$_time"
},
"last1": {
"$last": "$_time"
},
"HTTP_REFERER_HOST": {
"$first": "$HTTP_REFERER_HOST"
}
}
},
{
"$project": {
"length": {
"$subtract": ["$last1","$first1"]
},
"HTTP_REFERER_HOST": 1
}
},
{
"$group": {
"_id": "$HTTP_REFERER_HOST",
"length": {
"$avg": "$length"
}
}
}
]
}
完整的错误是:
错误:
Assert: command failed: {
"ok" : 0,
"errmsg" : "cant $subtract atimestamp from a timestamp",
"code" : 16556,
"codeName" : "Location16556"
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
@(shell):1:1