Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB-错误“;查询结果太多,截断输出“;用$geoNear_Mongodb_Mongodb Query_Mongodb Java - Fatal编程技术网

MongoDB-错误“;查询结果太多,截断输出“;用$geoNear

MongoDB-错误“;查询结果太多,截断输出“;用$geoNear,mongodb,mongodb-query,mongodb-java,Mongodb,Mongodb Query,Mongodb Java,我正在我的分片集群上运行一个查询(6个节点,每个节点有3个副本集,2个shardsvr和1个仲裁器)。 我预计查询将返回110万个文档。我只收到约130.xxx文件。我正在使用Java驱动程序发出查询并处理数据(目前,我只计算返回的文档)。我正在使用MongoDB 3.2.9和最新的java驱动程序 mongod日志显示以下错误,该错误是由输出文档大于16MB引起的: 2016-10-10T12:00:22.933+0200 W COMMAND [conn22] Too many geoNea

我正在我的分片集群上运行一个查询(6个节点,每个节点有3个副本集,2个shardsvr和1个仲裁器)。 我预计查询将返回110万个文档。我只收到约130.xxx文件。我正在使用Java驱动程序发出查询并处理数据(目前,我只计算返回的文档)。我正在使用MongoDB 3.2.9和最新的java驱动程序

mongod日志显示以下错误,该错误是由输出文档大于16MB引起的:

2016-10-10T12:00:22.933+0200 W COMMAND  [conn22] Too many geoNear results for query { location: { $nearSphere: { type: "Point", coordinates: [ 10.xxxx, 52.xxxxx] }, $maxDistance: 3900.0 } }, truncating output.
2016-10-10T12:00:22.951+0200 I COMMAND  [conn22] command mydb.data command: geoNear { geoNear: "data", near: { type: "Point", coordinates: [ 10.xxxx, 52.xxxxx ] }, 
    num: 50000000, maxDistance: 3900.0, query: {}, spherical: true, distanceMultiplier: 1.0, includeLocs: true } keyUpdates:0 writeConflicts:0 numYields:890 reslen:16777310 
    locks:{ Global: { acquireCount: { r: 1784 } }, Database: { acquireCount: { r: 892 } }, Collection: { acquireCount: { r: 892 } } } protocol:op_query 589ms

2016-10-10T12:00:23.183+0200 I COMMAND  [conn22] getmore mydb.data query: { aggregate: "data", pipeline: [ { $geoNear: { near: { type: "Point", coordinates: [ 10.xxxx, 52.xxxxx ] }, 
    distanceField: "dist.calculated", limit: 50000000, maxDistance: 3900.0, query: {}, spherical: true, distanceMultiplier: 1.0, includeLocs: "dist.location" } }, { $project: { _id: false, 
    dist: { calculated: true } } } ], fromRouter: true, cursor: { batchSize: 0 } } cursorid:170255616227 ntoreturn:0 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:0 nreturned:43558 
    reslen:1568108 locks:{ Global: { acquireCount: { r: 1786 } }, Database: { acquireCount: { r: 893 } }, Collection: { acquireCount: { r: 893 } } } 820ms
查询:

db.data.aggregate([
   {
      $geoNear:{
         near:{
            type:"Point",
            coordinates:[
               10.xxxx,
               52.xxxxx
            ]
         },
         distanceField:"dist.calculated",
         maxDistance:3900,
         num:50000000,
         includeLocs:"dist.location",
         spherical:true
      }
   }
])
请注意,我发出了带有和不带参数
num
的查询,这两个查询都失败,出现了上面显示的错误

我希望一旦超过文档大小限制(16MB),查询将返回数据库块。 我错过了什么?如何检索所有数据

编辑: 当我添加一个组阶段时,mongod日志中的相同错误也导致查询失败:

db.data.aggregate([
   {
      $geoNear:{
         near:{
            type:"Point",
            coordinates:[
               10.xxxx,
               52.xxxxxx
            ]
         },
         distanceField:"dist.calculated",
         maxDistance:3900,
         includeLocs:"dist.location",
         num:2000000,
         spherical:true
      }
   },
   {
      $group:{
         _id:"$root_document"
      }
   }
])

同时,MongoDB工作人员方伦刚已经回答了我关于MongoDB用户组的询问。以下是他的答案:

目前,“geoNear”聚合阶段仅限于返回 结果在16MB BSON大小限制内。这与 MongoDB早期版本的一个问题(如中所述) ).你的问题击中了这个 问题,因为“geoNear”返回单个文档(包含数组 以及“allowDiskUse”聚合管道 不幸的是,该选项在这种情况下没有帮助

可以考虑两种选择:

如果您不需要所有的结果,您可以限制“geoNear” 如果需要,使用num、limit或maxDistance选项聚合结果大小 如果需要所有结果,可以使用find()运算符 不限于BSON最大大小,因为它返回游标。 下面是我在MongoDB 3.2.10上做的一个测试,仅供参考

为指定集合创建“2dsphere”:
db.coll.createIndex({location:'2dsphere'})
创建并插入几个大文档:
var padding='';
对于(var j=0;j<15;j++){
对于(变量i=1024*128;i>0;--i){
var padding=padding+'12345678';
}
}

 db.coll.insert({location:{type:"Point", coordinates:[-73.861, 40.73]}, padding:padding})
 db.coll.insert({location:{type:"Point", coordinates:[-73.862, 40.73]}, padding:padding})
 db.coll.insert({location:{type:"Point", coordinates:[-73.863, 40.73]}, padding:padding})
 db.coll.insert({location:{type:"Point", coordinates:[-73.864, 40.73]}, padding:padding})
 db.coll.insert({location:{type:"Point", coordinates:[-73.865, 40.73]}, padding:padding})
 db.coll.insert({location:{type:"Point", coordinates:[-73.866, 40.73]}, padding:padding}) Query using “geoNear” and server log shows “Too many geoNear results …, truncating output”
 db.coll.aggregate(
     [
         {
             $geoNear:{
                 near:{type:"Point", coordinates:[-73.86, 40.73]},
                 distanceField:"dist.calculated",
                 maxDistance:150000000,
                 spherical:true
             }
         },
         {$project: {location:1}}
     ]
 ) Query using “find” and all expected documents are returned
 // This and following "var" are necessary to avoid the screen being flushed by padding string.
 var cursor = db.coll.find (
     {
         location: {
             $near: {
                 $geometry:{type:"Point", coordinates:[-73.86, 40.73]},
                 maxDistance:150000,
             }
         }
     }
 )

 // It is necessary to iterate through the cursor. Otherwise, the query is not actually executed.
 var x = cursor.next()
 x._id
 var x = cursor.next()
 x._id
 ... 
你好,伦刚