Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/Akka.Persistence.MongoDb/Snapshot/MongoDbSnapshotStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,22 @@ private IMongoDatabase GetMongoDb()

private async Task<IMongoCollection<SnapshotEntry>> GetSnapshotCollection(CancellationToken token)
{
_snapshotCollection_DoNotUseDirectly = GetMongoDb().GetCollection<SnapshotEntry>(_settings.Collection);

if (!_settings.AutoInitialize)
if (_snapshotCollection_DoNotUseDirectly is not null)
return _snapshotCollection_DoNotUseDirectly;

var modelWithAscendingPersistenceIdAndDescendingSequenceNr =
new CreateIndexModel<SnapshotEntry>(Builders<SnapshotEntry>.IndexKeys
.Ascending(entry => entry.PersistenceId)
.Descending(entry => entry.SequenceNr));

await _snapshotCollection_DoNotUseDirectly.Indexes
.CreateOneAsync(modelWithAscendingPersistenceIdAndDescendingSequenceNr,
cancellationToken: token);
_snapshotCollection_DoNotUseDirectly = GetMongoDb().GetCollection<SnapshotEntry>(_settings.Collection);

if (_settings.AutoInitialize)
{
var modelWithAscendingPersistenceIdAndDescendingSequenceNr =
new CreateIndexModel<SnapshotEntry>(Builders<SnapshotEntry>.IndexKeys
.Ascending(entry => entry.PersistenceId)
.Descending(entry => entry.SequenceNr));

await _snapshotCollection_DoNotUseDirectly.Indexes
.CreateOneAsync(modelWithAscendingPersistenceIdAndDescendingSequenceNr,
cancellationToken: token);
}

return _snapshotCollection_DoNotUseDirectly;
}
Expand Down
Loading