ObjectId Atlas search doesn't work

Hi, I was trying to query an atlas search Index. The datatype is objectId and the index contains other paths which has autocomplete datatype. When I try to query the index using equals operator for the path that has objectId datatype, nothing is being returned. The Index definition is as follows

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "hscode": {
        "foldDiacritics": true,
        "maxGrams": 4,
        "minGrams": 1,
        "tokenization": "edgeGram",
        "type": "autocomplete"
      },
      "title": {
        "foldDiacritics": true,
        "maxGrams": 10,
        "minGrams": 2,
        "tokenization": "edgeGram",
        "type": "autocomplete"
      },
      "type._id": {
        "type": "objectId"
      }
    }
  }
}

The query details are as follows

db.categories.aggregate([
    {
        $search:{
            index:"categorySearch",
            equals:{
                path:"type._id",
                value:ObjectId("61711b4275e9397ec79bdfed")
            }
        }
    }
])

Note : The autocomplete queries are working without a problem

For those who are facing this issue, change the dot notation in the index definition to an object. So,

type._id:{type:ObjectId()}

should be changed to

type:{_id:{type:ObjectId()}}
1 Like

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