0

I am trying to use mongoose geospatial queries on the mongodb collection. "2dsphere" index is already applied on the location object.

Query

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);

Data

One of the many documents looks like below:

{
    "_id" : ObjectId("5c64511a04ede20c28f6ef0b"),
    "location" : {
        "coordinates" : [ 
            92.747338, 
            11.675442
        ],
        "type" : "Point"
    },
    "name" : "Test name",
}

What I've tried

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?

M. Twarog
  • 2,418
  • 3
  • 21
  • 39
Ashy Ashcsi
  • 1,529
  • 7
  • 22
  • 54

1 Answers1

0

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.

Ashy Ashcsi
  • 1,529
  • 7
  • 22
  • 54