Exception while adding second text index on MongoDB collection
I have two columns title & content. As of today I have added text index on my title column and today i am trying to add another index for content column but I am getting the following exception while doing it
> db.posts.createIndex({"title":"text","content":"text", "description":"text"})
{
"ok" : 0,
"errmsg" : "Index: { v: 2, key: { _fts: \"text\", _ftsx: 1 }, name: \"title_text_content_text_description_text\", ns: \"stress-test.posts\", weights: { content: 1, description: 1, title: 1 }, default_language: \"english\", language_override: \"language\", textIndexVersion: 3 } already exists with different options: { v: 2, key: { _fts: \"text\", _ftsx: 1 }, name: \"title_text\", ns: \"stress-test.posts\", weights: { title: 1 }, default_language: \"english\", language_override: \"language\", textIndexVersion: 3 }",
"code" : 85,
"codeName" : "IndexOptionsConflict"
}
1 Answer
7 years ago by Divya
To do this, you need to drop the current text index and create a new text index with all the columns you need.
Run the following steps to do that
db.posts.dropIndex("title_text")
db.posts.createIndex({"title":"text","content":"text", "description":"text"})
7 years ago by Karthik Divi