我在服务器上进行了复制,因为mongoDB仅允许复制中的多文档事务。之后,我尝试启动此代码:
db_client = pymongo.MongoClient('localhost', 27000)
col = db_client['test_db']['test_col']
with db_client.start_session() as session:
with session.start_transaction():
for i in range(10):
col.insert_one({'msg': i}, session = session)
if i == 8:
raise Exception
我认为它不应该向数据库写入任何内容,因为在块with session.start_transaction():
中会发生异常,必须将其称为session.abort_transaction()。
但是我遇到了我无法解释的错误:
pymongo.errors.OperationFailure: BSON field 'insert.startTransaction' is an unknown field.