時間:2024-02-07 12:09作者:下載吧人氣:25
我們在使用 MongoDB 的時候,會出現需要給一個已經存在的大集合的某個字段增加索引的情況。
索引分為前臺索引和后臺索引,對應到 pymongo 中創建索引的代碼:
import pymongo
handler = pymongo.MongoClient().yourdb.yourcol
# 前臺索引
handler.create_index(‘字段名‘)
# 后臺索引
handler.create_index(‘字段名‘, background=True)
網友評論