spring-projects / spring-projects/spring-data-mongodb

Add support for MongoDB backed counters.

Open
#4,823 14 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: pending-design-work theme: 5.1 type: enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.