Mongodb创建索引.

添加唯一索引.

from pymongo import MongoClient

# 给 coll 的 test_id 字段创建唯一索引
client = MongoClient('host', port=27017)
coll = client['db']['coll']
coll.ensure_index('test_id', unique=True)
Last modification:February 21st, 2020 at 03:29 pm