Not able to add search index after adding a new field inside a existing field in schema

specializations: [specializationsSchema],
const specializationsSchema = new mongoose.Schema({
  specialityId: {
    type: String,
    required: true,
  },
  specialityName: {
    type: String,
    required: true,
  },
  status: {
    type: String,
    enum: ['active', 'inactive'],
    default: 'active'
  }
})

here ‘specialityName’ field is added later but not able to add the search index for this

Hi @curaster_app and welcome to MongoDB community forums!!

Based on my understanding from the above posts, I tried to replicate the issue in my test Atlas cluster with version 6.0.5 using the following steps:

  1. Create a new document as:
{
    _id: ObjectId("644f59e524564d038dd192d7"),
    specialityId: '12334567',
    status: [ 'active', 'inactive' ]
  }
  1. Add the new field to the above collection using:
db.searchAtlas.updateOne( 
         { specialityId: '12334567'}, 
         { $set: { "specialityName": "ABC"}})
  1. Create search index on the specialityName fields
{
  "analyzer": "lucene.whitespace",
  "searchAnalyzer": "lucene.whitespace",
  "mappings": {
    "dynamic": false,
    "fields": {
      "specialityName": {
        "type": "document"
      }
    }
  }
}

I was successfully able to create the search index for the fields. Therefore to understand your concern better, could you help me with the few details below.

  1. Steps to reproduce the issue if it different from the above steps posted.
  2. Search index definition.
  3. Error message been observed.

Regards
Aasawari

1 Like