Skip to content

Commit 156a004

Browse files
authored
Merge pull request #1921 from afumagalli98/fix-alert-version
Fixed alerts API to keep compatibility with mongo version <5
2 parents 2b2de2d + d527da5 commit 156a004

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

api-service/database/alerts.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,16 @@ func (md *MongoDatabase) SearchAlerts(alertFilter alert_filter.Alert) (*dto.Pagi
183183
bson.M{
184184
"$addFields": bson.M{
185185
"daysFromCreation": bson.M{
186-
"$dateDiff": bson.M{
187-
"startDate": "$date",
188-
"endDate": "$$NOW",
189-
"unit": "day",
186+
"$trunc": bson.M{
187+
"$divide": bson.A{
188+
bson.M{
189+
"$subtract": bson.A{
190+
"$$NOW",
191+
"$date",
192+
},
193+
},
194+
24 * 60 * 60 * 1000, // number of milliseconds in a day
195+
},
190196
},
191197
},
192198
},

0 commit comments

Comments
 (0)