spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

maxTimeMs in MongoTemplate.findAndModify(...) is not being honored.

Open sriram-1729 opened this issue 1 year ago • 1 comments

JDK: Amazon Coretto 17.0.12 MongoDB version: 7.0.14 spring-data-mongodb version: 4.3.3

Sample code:

Criteria criteria = Criteria.where("name").is(name);
Query query = Query.query(criteria);
query.maxTimeMsec(5L);
Update update = Update.update("lastFetchedAt", new Date());
FindAndModifyOptions findAndModifyOptions = FindAndModifyOptions.options().returnNew(true);
return mongoTemplate.findAndModify(query, update, findAndModifyOptions, ExampleModel.class);

From the above, it is expected that the query to fetch the document should time out after 5ms, but this is not what happens. The maxTimeMsec set is ignored, and the document gets updated.

If the following command is run through mongosh:

db.runCommand({findAndModify: "example", query: {"name": "example100000"}, update: {"lastFetchedAt": new Date()}, maxTimeMS: 5})

we get the following error:

MongoServerError[MaxTimeMSExpired]: Plan executor error during findAndModify :: caused by :: operation exceeded time limit

This is similar to issue #4374, but here maxTimeMs cannot be carried forward to UpdateOptions.

sriram-1729 avatar Sep 02 '24 13:09 sriram-1729

thank you for reporting - we'll have a look.

christophstrobl avatar Sep 03 '24 04:09 christophstrobl