@@ -301,11 +301,29 @@ public void addGidIndexesUnique(MongockTemplate mongoTemplate) {
301
301
ensureIndexes (mongoTemplate ,LibraryQuery .class ,makeIndex ("gid" ).unique ());
302
302
}
303
303
304
+ private int getMongoDBVersion (MongockTemplate mongoTemplate ) {
305
+ Document buildInfo =mongoTemplate .executeCommand (new Document ("buildInfo" ,1 ));
306
+ String versionString =buildInfo .getString ("version" );
307
+ if (versionString ==null )return -1 ;
308
+ String []versionParts =versionString .split ("\\ ." );
309
+ int majorVersion =Integer .parseInt (versionParts [0 ]);
310
+ return majorVersion ;
311
+ }
312
+
304
313
@ ChangeSet (order ="026" ,id ="add-time-series-snapshot-history" ,author ="" )
305
314
public void addTimeSeriesSnapshotHistory (MongockTemplate mongoTemplate ,CommonConfig commonConfig ) {
315
+ int mongoVersion =getMongoDBVersion (mongoTemplate );
316
+ if (mongoVersion <5 ) {
317
+ log .warn ("MongoDB version is below 5. Time-series collections are not supported. Upgrade the MongoDB version." );
318
+ }
319
+
306
320
// Create the time-series collection if it doesn't exist
307
321
if (!mongoTemplate .collectionExists (ApplicationHistorySnapshotTS .class )) {
308
- mongoTemplate .createCollection (ApplicationHistorySnapshotTS .class ,CollectionOptions .empty ().timeSeries ("createdAt" ));
322
+ if (mongoVersion <5 ) {
323
+ mongoTemplate .createCollection (ApplicationHistorySnapshotTS .class ,CollectionOptions .empty ().timeSeries ("createdAt" ));
324
+ }else {
325
+ mongoTemplate .createCollection (ApplicationHistorySnapshotTS .class );
326
+ }
309
327
}
310
328
Instant thresholdDate =Instant .now ().minus (commonConfig .getQuery ().getAppSnapshotKeepDuration (),ChronoUnit .DAYS );
311
329
List <ApplicationHistorySnapshot >snapshots =mongoTemplate .find (new Query ().addCriteria (Criteria .where ("createdAt" ).gte (thresholdDate )),ApplicationHistorySnapshot .class );