spring-projects / spring-projects/spring-data-mongodb
Add support for MongoDB backed counters.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
The goal of this issue is to help users manage server side counters more easily.
We could leverage findAndUpdate that issues an update with $inc, upsert and ReturnDocument.AFTER to maintain a counter document in a specific collection obtaining the incremented value as outlined below.
return mongoTemplate.execute("sequence_collection", collection -> {
return collection.findOneAndUpdate(new Document("_id", sequenceName), new Document("$inc", new Document("count", 1)), new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)).getLong("count");
});
Wrapping the above in something like a MongoSequence would allow easy access.
This issue is somehow related to #1842 which IMO should be addressed on a broader basis in data-commons.
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.
Research direction
Start with the proposed mongoTemplate.execute call and the related data-commons issue #1842. Determine how a MongoSequence-style API should fit the existing Spring Data MongoDB abstractions, then verify that the chosen collection can atomically increment and return a counter value as described; the issue does not name implementation files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mongodb, spring
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100