i'm experimenting with mongodb and geospatial queries. I made the following collection:
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 ] ] ]
}
}
]
then i tried the following:
var square = db.shape.find({name :"square"});
db.shape.find({structure : { $geoWithin : { $geometry : square.structure}}});
and i get this error:
MongoServerError: unknown geo specifier: $geometry: null
why is $geometry null?
Thanks in advance