spring-projects / spring-projects/spring-data-mongodb
maxTimeMs in MongoTemplate.findAndModify(...) is not being honored.
@christophstrobl is already working on this.
Since Sep 3, 2024.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.