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)中的半径属性,如下所示:

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 回答