I am trying to use mongoose geospatial queries on the mongodb collection. "2dsphere" index is already applied on the location object.
Please find the query below:
const data = await Banks.find(
{
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [73.8567, 18.5204]
},
$maxDistance: 10000000
}
}
}
);
console.log('-- the data --', data);
One of the many documents looks like below:
{
"_id" : ObjectId("5c64511a04ede20c28f6ef0b"),
"location" : {
"coordinates" : [
92.747338,
11.675442
],
"type" : "Point"
},
"name" : "Test name",
}
I have tried to set max distance as big as possible. But the query does not retrieve any documents back. What could be the problem?
The query mentioned above works fine. I had been referring to wrong Model Name(collection). The collection name was banks and I had been referring as Banks. The Model Name's are case sensitive in MongoDB.