我编写了以下程序来连接我的 mongo 数据库
from flask import Flask
from flask_mongoalchemy import MongoAlchemy
app = Flask(__name__)
app.config['MONGOALCHEMY_DATABASE']='MyDatabase'
app.config['MONGOALCHEMY_CONNECTION_STRING']='mongodb://<username>:<password>@mycluster-shard-00-00-cfkbg.mongodb.net:27017,mycluster-shard-00-01-cfkbg.mongodb.net:27017,mycluster-shard-00-02-cfkbg.mongodb.net:27017/test?ssl=true&replicaSet=MyCluster-shard-0&authSource=admin&retryWrites=true&w=majority'
db=MongoAlchemy(app)
class Example(db.Document):
name=db.StringField()
if __name__=='__main__':
obj=Example(name='Aman')
obj.save()
错误:
Traceback (most recent call last):
File "app.py", line 15, in <module>
obj.save()
File "/usr/local/lib/python3.6/dist-packages/flask_mongoalchemy/__init__.py", line 271, in save
self._session.insert(self, safe=safe)
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/session.py", line 172, in insert
self.add(item, safe=safe)
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/session.py", line 188, in add
return self.flush()
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/session.py", line 414, in flush
result = op.execute()
File "/usr/local/lib/python3.6/dist-packages/mongoalchemy/ops.py", line 97, in execute
return self.collection.save(self.data, safe=self.safe)
File "/usr/local/lib/python3.6/dist-packages/pymongo/collection.py", line 1881, in save
write_concern = WriteConcern(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'safe'