I have collection with some daily statistics and I want to use aggregation framework in mongo. Now I faced a problem with sorting/grouping Integer64 (type 18) with each other and I want to ask for some help:
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 works well with Integer32 (type 16), but not with 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
}
P.S. MongoDB shell version: 2.2.1
This likely means that you have some docs in your collection where
_id.appIdcontains an array of Integer64s instead of a single Integer64.A query object of
{"_id.appId": {$type:18}}will match either due to SERVER-1475.