/**
* Fetches the most recent version of a stream.
* @return the most recent version.
* @param eventStreamId
*/
public long getMostRecentStreamVersion(String eventStreamId) {
MongoCollection<Document> casualStreams = database.getCollection(CASUAL_STREAMS_COLLECTION);
AggregateIterable<Document> aggregate = casualStreams.aggregate(
Lists.newArrayList(
new Document("$match",
new Document("_id", new ObjectId(eventStreamId))
),
new Document("$group",
new Document("_id", "$_id")
.append("maxVersion", new Document("$max", "$version_"))
)
)
);
return Optional
.ofNullable(aggregate.first())
.map(d -> d.getLong("maxVersion"))
.orElse(0L);
}
MongoDBEventSourcingRepository.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:casual-eventsourcing
作者:
评论列表
文章目录