時(shí)間:2024-02-07 12:09作者:下載吧人氣:35
我們?cè)谑褂?MongoDB 的時(shí)候,會(huì)出現(xiàn)需要給一個(gè)已經(jīng)存在的大集合的某個(gè)字段增加索引的情況。
索引分為前臺(tái)索引和后臺(tái)索引,對(duì)應(yīng)到 pymongo 中創(chuàng)建索引的代碼:
import pymongo
handler = pymongo.MongoClient().yourdb.yourcol
# 前臺(tái)索引
handler.create_index(‘字段名‘)
# 后臺(tái)索引
handler.create_index(‘字段名‘, background=True)
網(wǎng)友評(píng)論