2013-01-31 55 views
0

我收集了一些日常統計數據,我想在mongo中使用聚合框架。現在我面臨的一個問題,互相整理/分組Integer64(18型),我想尋求一些幫助:MongoDB無法比較Integer64的

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 
} 

排序與整數(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

+0

我發現錯誤報告:https://jira.mongodb.org/browse/SERVER-5209 –

+0

你有一個文檔,其中'_id.appId'(意外)是一個Int64數組嗎? '{$ type:18}'實際上也會匹配。 – JohnnyHK

+0

@JohnnyHK,我該如何檢查? –

回答

1

這可能意味着您的集合中有一些文檔,其中_id.appId包含Integer64數組而不是單個Integer64。

由於SERVER-1475{"_id.appId": {$type:18}}的查詢對象將匹配。