Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MongoDB backed counters. #4823

Open
christophstrobl opened this issue Oct 28, 2024 · 0 comments
Open

Add support for MongoDB backed counters. #4823

christophstrobl opened this issue Oct 28, 2024 · 0 comments
Labels
theme: 5.0 type: enhancement A general enhancement

Comments

@christophstrobl
Copy link
Member

christophstrobl commented Oct 28, 2024

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.

@christophstrobl christophstrobl changed the title Add support for MongoDB backed sequences. Add support for MongoDB backed counters. Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: 5.0 type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant