我有一些这样的代码片段:
from flask import Flask
from flask_pymongo import PyMongo
from pymongo import InsertOne, UpdateOne, DeleteOne, ReplaceOne
from flask import jsonify
app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'MyDB'
mongo = PyMongo(app)
coll = mongo.db['collection1']
requests = []
for d in data_to_delete:
requests.append(DeleteOne({'key1': d}))
result = coll.bulk_writes(requests)
return jsonify(result=result.deleted_count)
当我尝试执行它时,我收到错误消息:
TypeError: 'Collection' object is not callable. If you meant to call the 'bulk_writes' method on a 'Collection' object it is failing because no such method exists.
PyMongo 文档说Collection
object 有这个方法,虽然我知道这Flask-Pymongo
是一个PyMongo
. 可能是什么问题,我如何使用bulk_writes()
集合Flask-Pymongo
?
谢谢您的帮助!