How to make $geoIntersects work for the “legacy coordinates pair”

How to make $geoIntersects work for the “legacy coordinates pair”?

it is simple to find the user’s current neighborhood with $geoIntersects.

Trying to make/adapt the following find by $geoIntersects work with the “legacy coordinates pair” –
db.neighborhoods.findOne({ geometry: { $geoIntersects: { $geometry: { type: "Point", coordinates: [ -73.93414657, 40.82302903 ] } } } })

but I always get null results, even I surely know there is a match.

Suppose the user is located at -73.93414657 longitude and 40.82302903 latitude. To find the current neighborhood, you will specify a point using the special $geometry field in GeoJSON format.

I guess, on top of the above requirement, the field used for the $geoIntersects lookup must be in GeoJSON format as well, (unlike $geoWithin or $nearSphere), right?

So, if my collection uses the legacy coordinates pair, like the sample_restaurants from sample db, is there any way for me to use the $geometry query please?

Hey @MBee,

I tried the same query against the sample_restaurants.neighborhoods collection. It worked as expected and returned the following document as output:

  _id: ObjectId("55cb9c666c522cafdb053a68"),
  geometry: {
    coordinates: [
        ... 248 more items
    type: 'Polygon'
  name: 'Central Harlem North-Polo Grounds'

Please double-check that you are running the query against the correct collection, and ensure that your collection contains the correct set of data for accurate results.

Best regards,

Ah, you’re right. I made a tiny mistake when trying the above.
Thanks for the confirmation.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.