0

Help me please! I have a problem with query in mongodb. I want to return data with distance from my location to location of place (have multiple location). My data in mongodb as:

 [{
    "name" : "Bob",
    "place" : [ 
        {
            "location" : {
                "type" : "Point",
                "coordinates" : [ 
                    106, 
                    10
                ]
            }
        }, 
        {
            "location" : {
                "type" : "Point",
                "coordinates" : [ 
                    106, 
                    10
                ]
            }
        }
    ]
}]

And I can't get distance for each "location" in "place". I want to return data as

[{
    "name" : "Bob",
    "place" : [ 
        {
            "location" : {
                "type" : "Point",
                "coordinates" : [ 
                    106, 
                    10
                ]
            },
           "distance":5322
        }, 
        {
            "location" : {
                "type" : "Point",
                "coordinates" : [ 
                    106, 
                    10
                ]
            },
           "distance":2345
        }
    ]
}]
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • MongoDB can return the distance from a "queried point". But what are these "distances" meant to be from? A point? Each other? – Neil Lunn May 11 '18 at 08:19
  • "distance" is value return by calculate distance from my location to place location. In mysql i can calculate it – Thiên Long May 11 '18 at 08:26

0 Answers0