Skip to content

Commit

Permalink
mongo: Fix GetMigrationInfo returning sorted results
Browse files Browse the repository at this point in the history
changelog: none

Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
  • Loading branch information
alfrunes committed Mar 24, 2021
1 parent 43ce65d commit 71dbbe0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mongo/migrate/db.go
@@ -1,4 +1,4 @@
// Copyright 2020 Northern.tech AS
// Copyright 2021 Northern.tech AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,15 +40,17 @@ type MigrationEntry struct {
func GetMigrationInfo(ctx context.Context, sess *mongo.Client, db string) ([]MigrationEntry, error) {
c := sess.Database(db).Collection(DbMigrationsColl)
findOpts := mopts.Find()
findOpts.SetSort(bson.M{
"version.major": -1,
"version.minor": -1,
"version.patch": -1,
})
findOpts.SetSort(bson.D{{
Key: "version.major", Value: -1,
}, {
Key: "version.minor", Value: -1,
}, {
Key: "version.patch", Value: -1,
}})

cursor, err := c.Find(ctx, bson.M{
"version": bson.M{"$exists": true},
})
}, findOpts)
if cursor == nil || err != nil {
return nil, errors.Wrap(err, "db: failed to get migration info")
}
Expand Down

0 comments on commit 71dbbe0

Please sign in to comment.