2016-10-10 6 views
1

私は私のシャードクラスタ上$geoNearクエリを実行している(3レプリカと6つのノードが2 shardsvrと1つのアービタのそれぞれを設定します)。 私はクエリが1.1m文書を返すと期待しています。私は〜130.xxxの書類しか受け取りません。私は、Javaドライバを使用してクエリを発行し、データを処理しています(今のところ、返されるドキュメントを数えています)。私はMongoDB 3.2.9と最新のJavaドライバを使用しています。

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 
     } 
    } 
]) 

のmongodログは、16メガバイトよりも大きくなった出力文書によって引き起こされる、次のエラーを示していパラメータnumは、上記のエラーで両方とも失敗します。

ドキュメントサイズ制限(16 MB)を超えた場合、クエリでデータベースのチャンクが返されると予想されました。 私は何が欠けていますか?すべてのデータを取得するにはどうすればよいですか?

編集: 私はグループステージを追加するときに、クエリもの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" 
     } 
    } 
]) 
Lungang牙でのMongoDBユーザーグループの私の問い合わせに応答した

答えて

1

MongoDBのスタッフメンバーその間。現在

、「geoNear」集約ステージは16メガバイトのBSONサイズの制限内にある 結果を返すように制限されます。以下は彼の答えです。これは、 のMongoDBの以前のバージョン( https://jira.mongodb.org/browse/SERVER-13486に記載されています)に関する問題です。 "geoNear"が単一のドキュメント(結果ドキュメントの の配列を含む)を返し、 "allowDiskUse"集約パイプライン オプションが残念なことにこのような場合に役立たないため、クエリでは の問題が発生しました。

考えることができる2つのオプションがあります:あなたはすべての結果を必要としない場合は

、あなたが必要と 場合NUM、制限、またはmaxDistanceオプションを使用して「geoNear」 集計結果のサイズを制限する可能性がすべての結果では、 がカーソルを返すので、BSONの最大サイズに限定されないfind()演算子を使用することができます。 以下はMongoDB 3.2.10で行ったテストです。

「2dsphere」指定された収集のために作成します。いくつかの大きな文書を作成し、挿入 db.coll.createIndex({location: '2dsphere'})
var padding = ''; for (var j = 0; j < 15; j++) { for (var 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 
... 

よろしく、Lungang

関連する問題