我正在试验 mongodb 和地理空间查询。我做了以下收藏:
shape> db.shape.find()
[
{
_id: ObjectId("61ab50d2056b5357b5e23e56"),
name: 'Point1',
structure: { type: 'Point', coordinates: [ 2.5, 2.5 ] }
},
{
_id: ObjectId("61ab5337056b5357b5e23e57"),
name: 'Point2',
structure: { type: 'Point', coordinates: [ 5, 5 ] }
},
{
_id: ObjectId("61ab533e056b5357b5e23e58"),
name: 'Point3',
structure: { type: 'Point', coordinates: [ 9, 9 ] }
},
{
_id: ObjectId("61ab5b4d056b5357b5e23e64"),
name: 'square',
structure: {
type: 'Polygon',
coordinates: [ [ [ 0, 0 ], [ 0, 5 ], [ 5, 5 ], [ 5, 0 ], [ 0, 0 ] ] ]
}
}
]
然后我尝试了以下方法:
var square = db.shape.find({name :"square"});
db.shape.find({structure : { $geoWithin : { $geometry : square.structure}}});
我得到这个错误:
MongoServerError: unknown geo specifier: $geometry: null
为什么 $geometry 为空?
提前致谢