Is there an equivalent command to SQL "SET LOCAL statement_timeout"?

is there a way to set queries timeout with command within single transaction?
In other words, i’m looking for equivalent command to

SET LOCAL statement_timeout TO 200;

Thanks for a help in advance!

Hi @Mateusz_Glowinski and welcome to the MongoDB Community :muscle: !

I think you are looking for the wtimeout that you can set in the writeconcern parameter of the session.startTransaction function.


Thank you @MaBeuLux88 for a really nice hint, but this will not solve my problem.

What I’m actually trying to do, is to use djongo package to communicate with MongoDB. I want to get an database error, once a query takes too much time.
Something similar to this.

In Python (and equivalent in the other drivers of course) you have max_time_ms on cursors: cursor – Tools for iterating over MongoDB query results — PyMongo 4.3.3 documentation

There are also a bunch of timeouts that you can set in the connection string: (CTRL + F for “ms” to find them all).

I hope this helps,

1 Like

Thank you, that is exactly what i need!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.