mongodbmongoengine

How to set the maxidletimems for Mongoengine


The mongo library used in my project is Mongoengine

I often find the error 'pymongo. errors. CursorNotFound: Cursor not found' in the logs. After investigation, it was found that the mongo server actively closed the spatial link, and this error occurred when the link was used again. But I couldn't find an introduction to setting "maxIdleTimeMS" in the Mongoengine related documents.

Can someone help me


Solution

  • By the information here. You can setting maxIdleTimeMS by config MONGODB_MAXIDLETIMEMS. if you use MONGODB_SETTINGS, you would use maxidletimems

    Example:

    MONGODB_SETTINGS = {
        "db": os.getenv("MONGODB_DATABASE", "test"),
        "host": os.getenv(
            "MONGODB_URI",
            "mongodb://test:test@127.0.0.1:27017/test?replicaSet=rs0",
        ),
        "maxidletimems": int(os.getenv("MONGODB_MAXIDLETIMEMS", "12000"))
    }