How to get distance in array of location

Hello guys,

I am working on jobseeker app. Here companies come and create some Job Post

So, Job_Posting Schema :

{
    _id: 1,
    title : "Intern",
    post : "Testing",
    company_id : 2332,
    desc : "......",
    location : [
                { type: "Point", coordinates: [longitude, latitude] },
                { type: "Point", coordinates: [longitude, latitude] },
                { type: "Point", coordinates: [longitude, latitude] }
               ],
    someotherinfo : '......'
}

Now, I have latitude and longitude , I want the jobs record within a radius of 100 km

when I have saved one location in one record.
Then we can use geoNear,

But Here, How can I do .

Thanks :slight_smile:

Hi @Praveen_Gupta ,

What is the reason for having an array of geo points?

This array cannot be indexed with a regular 2d or 2dsphere indexes the way it is.

You can have them as a multipoint type:

{
  type: "MultiPoint",
  coordinates: [
     [ longitude, latitude ],
     [longitude, latitude  ],
     [ longitude, latitude ],
     [ longitude, latitude  ],
    ...
  ]
}

This should allow you to see if any of those point are in a radius of 100km…

If that does not work for you, Perhaps consider having a document per geo point if those all reference to the same company.

Ty
Pavel

Thanks @Pavel_Duchovny .
Can we save city name with these coordinates ?

Not sure what you mean?

Inside the geo object you can save only the geo format.

If you want to save an array of the cities you can.

Best
Pavel