Skip to content

Add support for MongoDB backed counters. #4823

Open
@christophstrobl

Description

@christophstrobl

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions