Find all the documents in Mongodb according to distance

33 views Asked by At

I have a collection of documents on the following format:

{
    "type" : "car",
    "distance" : 30,
    "location" : {
        "type" : "Point",
        "coordinates" : [ 
            51.7867481, 
            -0.2016516
        ]
    }
}

Each document has different coordinates (which are lat/long). Now, given another document of type

{
    "type" : "passenger",
    "location" : {
        "type" : "Point",
        "coordinates" : [ 
            47.7867481, 
            -2.2016516
        ]
    }
}

what is the best way to find out all the documents of type "car" that are withing the distance of the document type "passenger"

0

There are 0 answers