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 2d430a2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions mongo/migrate/db.go
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 2d430a2

Please sign in to comment.