Querying geojson Point using geoShape operator against indexed geojson Polygon does not return any results

Cluster: M10
MongoDB version: 5.0.22

Index geo_json_test:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "geo_filter": {
        "indexShapes": true,
        "type": "geo"
      }
    }
  }
}

Example of a document (Polygon around Paris):

{
"geo_filter": {
    "type": "Polygon",
    "is_location_exact": false,
    "coordinates": [
      [
        [
          2.464903,
          48.878079
        ],
        [
          2.413622,
          48.872461
        ],
        [
          2.38443,
          48.902156
        ],
        [
          2.351985,
          48.901493
        ],
        [
          2.319889,
          48.900459
        ],
        [
          2.27749,
          48.877963
        ],
        [
          2.23212,
          48.869554
        ],
        [
          2.224168,
          48.853442
        ],
        [
          2.262776,
          48.833918
        ],
        [
          2.2865482465437545,
          48.82264222452071
        ],
        [
          2.3080964747424617,
          48.811586780863934
        ],
        [
          2.3632943199824012,
          48.80929944307559
        ],
        [
          2.409361,
          48.816633
        ],
        [
          2.458633,
          48.817013
        ],
        [
          2.481826,
          48.861413
        ],
        [
          2.464903,
          48.878079
        ]
      ]
    ]
  },
}

Example of the $search aggregation stage (using Mongo Compass, Point is located in the Paris centre):

{
  index: 'geo_json_test',
  "geoShape": {
      "path": "geo_filter",
      "relation": "contains",
      "geometry": {
        type: "Point", 
        coordinates: [
          2.3490965777322117,
          48.856739774345755
      ]
    }
  } 
}

I expect this query to return this document, but there are not results.
Is there a mistake on my side or the bug on Atlas search side?

7 Likes

Hey @Stanislav_Slesarev,

Welcome to the MongoDB Community forums :sparkles:

I tested the sample documents you provided using the same Atlas Search index on the M10 Cluster Tier with the 5.0.23 version, and I received the following output. Here is the query I executed:

db.collection.aggregate([
  {
    '$search': {
      'index': 'geo_json_test', 
      'geoShape': {
        'path': 'geo_filter', 
        'relation': 'contains', 
        'geometry': {
          'type': 'Point', 
          'coordinates': [
            2.3490965777322117, 48.856739774345755
          ]
        }
      }
    }
  }
]);

and got the following output:

{
  _id: ObjectId("656708944e03dd3c8c791230"),
  geo_filter: {
    type: 'Polygon',
    is_location_exact: false,
    coordinates: [
      [
        [
          2.464903,
          48.878079
        ],
        ...
      ]
    ]
  }
}

I’d suggest double-checking the query you’re executing and ensuring that your Atlas Search index status is active. This can often resolve such issues.

Even if the issue persists, please share the error you are encountering along with the logs. This will provide a better understanding of the problem.

Best regards,
Kushagra

1 Like

good afternoon, Kushagra!

Thank you for a reply.
As you reassured my proof-of-concept should work, I basically retried this on our cluster and it works now.
I can definitely say the same setup did not bring me any results, and I triple-checked this before writing to the forum.

However, the next step for me was to verify if the same scenario works for geojson Polygon indexed as embdeddedDocument, and embdeddedDocument inside of embdeddedDocument.

Let me post example of the query, may be it will help someone in the future to avoid mistakes:

{
  'index': 'geo_filter_index',
  embeddedDocument: {
    path: "preferences",
    operator: {
      embeddedDocument: {
        path: "preferences.location_preferences",
        operator: {
          'geoShape': {
            'path': 'preferences.location_preferences.geojson', 
            'relation': 'contains', 
            'geometry': {
              'type': 'Point', 
              'coordinates': [
                2.3490965777322117, 48.856739774345755
              ]
            }
          }
        }
      }
    }
  }
}

Sorry for confusion and thank you for clarifications!

1 Like

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