/// <summary> /// Retrieve the latest commit matching the specified criteria /// </summary> /// <param name="streamId">Unique stream identifier</param> /// <param name="atBucketRevision">Get the last commit less or equal the specified bucket revision</param> /// <returns>Last commit info</returns> public async Task <CommitInfo> GetLastCommitAsync(Guid?streamId = null, long?atBucketRevision = null) { if (atBucketRevision <= 0) { throw new ArgumentOutOfRangeException(nameof(atBucketRevision), "Parameter must be greater than 0."); } var filter = Builders <CommitInfo> .Filter.Empty; if (streamId != null) { filter = filter & Builders <CommitInfo> .Filter.Eq(p => p.StreamId, streamId.Value); } if (atBucketRevision != null) { filter = filter & Builders <CommitInfo> .Filter.Lte(p => p.BucketRevision, atBucketRevision.Value); } var result = await InfoCollection .Find(filter) .Sort(Builders <CommitInfo> .Sort.Descending(p => p.BucketRevision)) .FirstOrDefaultAsync() .ConfigureAwait(false); return(result); }