我收集了一些日常统计数据,我想在 mongo 中使用聚合框架。现在我遇到了对 Integer64(类型 18)进行排序/分组的问题,我想寻求一些帮助:
mongos> db.daily_apps_totals.findOne({"_id.appId":{$type:16}})
{
"_id" : {
"datetime" : ISODate("2012-08-15T00:00:00Z"),
"appId" : 243,
},
...
}
mongos> db.daily_apps_totals.aggregate([ {$match: {"_id.datetime":ISODate("2013-01-28T00:00:00Z"), "_id.appId":{$type:16}}}, {$project:{_id:"$_id.appId"}}, {$sort: {_id:1}},{$limit:3}])
{
"result" : [
{
"_id" : 243
},
{
"_id" : 243
},
{
"_id" : 245
}
],
"ok" : 1
}
Sort 适用于 Integer32(类型 16),但不适用于 Integer64:
mongos> db.daily_apps_totals.findOne({"_id.appId":{$type:18}})
{
"_id" : {
"datetime" : ISODate("2012-08-15T00:00:00Z"),
"appId" : NumberLong(245),
},
...
}
mongos> db.daily_apps_totals.aggregate([ {$match: {"_id.datetime":ISODate("2013-01-28T00:00:00Z"), "_id.appId":{$type:18}}}, {$project:{_id:"$_id.appId"}}, {$sort: {_id:1}},{$limit:3}])
{
"errmsg" : "exception: can't compare values of BSON types Array and NumberLong64",
"code" : 16016,
"ok" : 0
}
PS MongoDB shell 版本:2.2.1