@@ -107,19 +107,22 @@ private IMongoDatabase GetMongoDb()
107107
108108 private async Task < IMongoCollection < SnapshotEntry > > GetSnapshotCollection ( CancellationToken token )
109109 {
110- _snapshotCollection_DoNotUseDirectly = GetMongoDb ( ) . GetCollection < SnapshotEntry > ( _settings . Collection ) ;
111-
112- if ( ! _settings . AutoInitialize )
110+ if ( _snapshotCollection_DoNotUseDirectly is not null )
113111 return _snapshotCollection_DoNotUseDirectly ;
114112
115- var modelWithAscendingPersistenceIdAndDescendingSequenceNr =
116- new CreateIndexModel < SnapshotEntry > ( Builders < SnapshotEntry > . IndexKeys
117- . Ascending ( entry => entry . PersistenceId )
118- . Descending ( entry => entry . SequenceNr ) ) ;
119-
120- await _snapshotCollection_DoNotUseDirectly . Indexes
121- . CreateOneAsync ( modelWithAscendingPersistenceIdAndDescendingSequenceNr ,
122- cancellationToken : token ) ;
113+ _snapshotCollection_DoNotUseDirectly = GetMongoDb ( ) . GetCollection < SnapshotEntry > ( _settings . Collection ) ;
114+
115+ if ( _settings . AutoInitialize )
116+ {
117+ var modelWithAscendingPersistenceIdAndDescendingSequenceNr =
118+ new CreateIndexModel < SnapshotEntry > ( Builders < SnapshotEntry > . IndexKeys
119+ . Ascending ( entry => entry . PersistenceId )
120+ . Descending ( entry => entry . SequenceNr ) ) ;
121+
122+ await _snapshotCollection_DoNotUseDirectly . Indexes
123+ . CreateOneAsync ( modelWithAscendingPersistenceIdAndDescendingSequenceNr ,
124+ cancellationToken : token ) ;
125+ }
123126
124127 return _snapshotCollection_DoNotUseDirectly ;
125128 }
0 commit comments