From 71dbbe049fcafa729f6ce44a0594a3988c19d185 Mon Sep 17 00:00:00 2001 From: Alf-Rune Siqveland Date: Wed, 24 Mar 2021 12:20:50 +0100 Subject: [PATCH] mongo: Fix GetMigrationInfo returning sorted results changelog: none Signed-off-by: Alf-Rune Siqveland --- mongo/migrate/db.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mongo/migrate/db.go b/mongo/migrate/db.go index 448bcc2e..da72c9b9 100644 --- a/mongo/migrate/db.go +++ b/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. @@ -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") }