I am currently working on a Golang codebase that uses MongoDB. What bothers me is that all the time a query is made, there is a new context.WithTimeout created. Let me give an example:
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
defer cancel()
collection := m.Client.Database(....
result := collection.FindOne(ctx, filter)
One way I tried to not use context is:
options.FindOne().SetMaxTime(defaultTimeout)
but when I tested, with some really small timeout(say 1 nanosecond), it did not result in a timeout? Do you have ideas about why it did not worked?
Also, is there some way to set such a timeout as a global option for all queries?
What about transactions?