bulk_write

可以批量进行如下:

  • InsertOne
  • UpdateOne
  • UpdateMany
  • ReplaceOne
  • DeleteOne
  • DeleteMany

    批量更新

    ```python import pymongo

bulk_data = []

for i in range(1000): name = f’s{i}’ _filter = {‘id’: i} _update = {‘$set’: {‘name’: name}} bulk_data.append(pymongo.UpdateOne(_filter, _update, upsert=True)) col.bulk_write(bulk_data)

  1. <a name="XIows"></a>
  2. #### 批量插入
  3. ```python
  4. bulk_data = []
  5. for i in range(1000):
  6. data = pymongo.InsertOne({'id', i, 'name': f's{i}'})
  7. bulk_data.append(data)
  8. col.bulk_write(bulk_data)