2
我有用戶採集:MongoDB:如何在查找查詢中使用屬性?
{
"_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" })
我需要寫的查詢和收集的行使用半徑屬性(「方圓」:1)在發現這樣的查詢:
db.user.find({ loc: { $geoWithin :{ $centerSphere : [ [0.7, 0.7 ] , radius ]} } })
但蒙戈的回報:
JavaScript execution failed: ReferenceError: radius is not defined
我已經試過db.user.find({ loc: { $geoWithin :{ $centerSphere : [ [0.7, 0.7 ] , this.radius ]} } })