我目前正在使用一个简单的python CRUD脚本来检查MongoDB。原来我很喜欢它,但是我发现自己无法使用MongoDB事务。每次我尝试开始交易时,都会引发一个异常:
This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.
而且,尽管我已经将该选项添加到了我的连接字符串中:
self._client = MongoClient('mongodb://localhost/?retryWrites=false')
self._db = self._client.workouts
self._collection = self._db.workouts
运行以下代码行时,该错误仍会弹出:
with self._client.start_session() as s:
with s.start_transaction():
self._collection.delete_one({'_id': id}, session=s)
next = self._collection.find_one({'_id': next_id}, session=s)
return next
我该怎么办?
我正在运行python 3.7.3,pymongo 3.9.0和MongoDB 4.0.12。