So, imagine these input documents:
[
{
"location": {
"type": "Point",
"coordinates": [
10,
20
]
},
"proximity": 0.001
},
{
"location": {
"type": "Point",
"coordinates": [
10,
30
]
},
"proximity": 0.005
}
]
When I want to filter with $geoWithin
and $centerSphere
, if I specify static radius, the query works:
db.collection.aggregate([
{
"$match": {
"location": {
"$geoWithin": {
"$centerSphere": [
[
10,
20
],
0.001
]
}
}
}
}
])
However, when I set radius dynamically based on some property, the query throws an error:
db.collection.aggregate([
{
"$match": {
"location": {
"$geoWithin": {
"$centerSphere": [
[
10,
20
],
"$proximity"
]
}
}
}
}
])
The error thrown is: radius must be a non-negative number
. What’s happening here?
I created this playground for testing.