2

私はユーザーコレクションを持っています:

{
  "_id": { "$oid" : "514C438232F5699004000014" },
  "gender": 1,
  "loc": {
    "coordinates": [
      0.777084,
      0.701690
    ],
    "type": "Point"
  },
  "name": "H1",
  "radius": 1
},

{
  "_id": { "$oid" : "514C438232F5699004000014" },
  "gender": 1,
  "loc": {
    "coordinates": [
      0.677084,
      0.701690
    ],
    "type": "Point"
  },
  "name": "H2",
  "radius": 0.4
}

db.user.ensureIndex( { loc : "2dsphere" } )

次のような検索クエリでクエリを作成し、コレクションの行 ( "radius": 1 ) から radius プロパティを使用する必要があります。

db.user.find( { loc: { $geoWithin :{ $centerSphere : [ [0.7, 0.7 ] , radius ]}   } } )

しかし、mongo は次のように返します。

JavaScript の実行に失敗しました: ReferenceError: 半径が定義されていません

私が試してみましたdb.user.find( { loc: { $geoWithin :{ $centerSphere : [ [0.7, 0.7 ] , this.radius ]} } } )

4

1 に答える 1

0

双方向のクエリを実行する必要があると思います。最初に特定のユーザーの半径を取得し、次にこの半径内のすべての場所を検索します。

于 2013-05-10T16:38:56.007 に答える