Unable to persist transaction state because the se

2019-08-29 07:02发布

I have accidentally dropped all databases from my mongo db. Then i tried to insert a document in new database. It throws error "Unable to persist transaction state because the session transaction collection is missing. This indicates that the config.transactions collection has been manually deleted."

My Sample code:

doc_client = MongoClient(host=host,
                         port=port,
                         connect=True,  # Connect on first operation to avoid multi-threading related errors
                         j=True,  # Requests only return once write has hit the DB journal
                         )
print(doc_client.database_names()) # It works fine
doc_client['test'].insert({'a': 'ss'}) # Throws Error

1条回答
欢心
2楼-- · 2019-08-29 07:09

I have accidentally dropped all databases from my mongo db

It is likely that you have also dropped config.transactions collection. This is a collection for internal usage that stores records used to support retryable writes for replica sets and sharded clusters. See also Config Databases.

Since MongoDB v3.6+, users won't be able to drop the config database in replica set from mongo shell. Although if you are connecting using mongo shell prior to v3.6, you're still able to do so, please ensure to upgrade the shell to match the server version.

"Unable to persist transaction state because the session transaction collection is missing. This indicates that the config.transactions collection has been manually deleted."

You can manually re-create the collection on the primary node:

use config
db.createCollection("transactions");

Alternatively, a replica set election would also automatically re-creates it. This is because the creation of config.transactions collection is part of a replica set node step up. session_catalog_mongod.cpp#L156

The new config.transactions collection will be replicated to the secondaries after the primary completed the catch up phase.

查看更多
登录 后发表回答