【发布时间】:2015-08-09 10:33:11
【问题描述】:
我正在尝试通过 pymongo 为我的 mongodb 集合应用索引。我正在使用
db[collection_name].ensure_index([("field_name" , "text"),("unique", 1), ("dropDups" , 1)])
它有效。但是现在如何将它应用到多个领域呢? 像这样的
db[collection_name].ensure_index([("field_name1" , "text"),("field_name2", "text"),("field_name3", "text"),("unique", 1), ("dropDups" , 1)])
我知道我们可以使用db.collection.ensureIndex({"$**":"text"},{"name":"TextIndex"})
在 mongo shell 中,但我不想索引所有字段。谁能帮帮我?
【问题讨论】:
-
您想要一个复合索引,还是在所需的文本字段上使用单独的索引?
-
我想通过python脚本做复合/复合索引