Reputation: 23883
I'm trying to create multiple indexes in MongoDB but no successful
collection.create_index([('text', 'text')])
collection.create_index([('main_text', 'text')])
Error message
OperationFailure: Index: { v: 2, key: { _fts: "text", _ftsx: 1 }, name: "main_text_text", ns: "5f67b1b60e27eb4ac456ebba_xxxxx.xxxxx", weights: { main_text: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 } already exists with different options: { v: 2, key: { _fts: "text", _ftsx: 1 }, name: "text_text", ns: "5f67b1b60e27eb4ac456ebba_xxxxx.xxxxx", weights: { text: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 }
Upvotes: 0
Views: 237
Reputation: 8814
As the commenter stated, you can't have more than 1 text index, but you can have multiple fields on a single text index, and this can be create in pymongo as follows:
import pymongo
db.collection.create_index([("text", pymongo.TEXT), ("main_text", pymongo.TEXT)])
Upvotes: 1