pymongo創建索引、更新、刪除
## collection 為數據集合
collection.create_Index({'需創建索引字段': 1})
collection.ensure_Index({'需創建索引字段': 1})
## 獲取索引信息,數據庫中使用
db.getCollection('tablename').getIndexes()
# 更新匹配到的第一條數據
collection.update_one(k, {'$set': v})
# 更新匹配到的所有數據
collection.update(k, v, {'multi': True})
collection.update_many(k, {'$set': v})
# 刪除指定字段
collection.update(k , {'$unset': {'需刪除的字段': 1}}, false, true)
# 刪除單條記錄
collection.delete_one(k)
# 刪除多條記錄
collection.delete_many(k)