I have a collection which contains documents like this:
{
"_id" : "cysMrqjootq6YS6WP",
“profile” : {
……
"deliveryDistance” : 20,
"address" : {
"loc" : {
"type" : "Point",
"coordinates" : [
—2.120361,
52.536273
]
} }
}
}
And I have a GeoJSON point like:
var referencePoint= {
"type" : "Point",
"coordinates" : [
—2.120361,
52.536273
]
}
I am using Meteor.js, Node.js and MongoDB. I would like to create a query where the maxDistance from this point is the deliveryDistance property from each document into my collection.
If the maxDistance was a fixed value, the query would be:
myCollection.find({
“profile.address.loc":{
"$nearSphere": {
"$geometry": referencePoint,
"$maxDistance": 20000 //for 20Kms
}
}
})
But this is not the case. For each document, the maxDistance has to be the value of ‘profile.deliveryDistance’. How do I use this value from the document as maxDistance in this query? Is it possible? If not, any other ideas?