From fd53c6669075eac0f2a04d4c416ba34411832890 Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Wed, 25 Mar 2020 17:40:26 +0100 Subject: [PATCH] Use ordered document for index model --- mongox/database/index.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mongox/database/index.go b/mongox/database/index.go index 8407b12..ff72ffa 100644 --- a/mongox/database/index.go +++ b/mongox/database/index.go @@ -64,15 +64,15 @@ func (d *Database) IndexEnsure(cfg interface{}, document interface{}) error { panic(fmt.Errorf("cannot evaluate index key")) } - index := primitive.M{key: 1} opts := &options.IndexOptions{ Background: &f, Unique: &f, Name: &name, } + index := primitive.D{{Key: key, Value: 1}} if indexValues[0] == "-" { - index[key] = -1 + index = primitive.D{{Key: key, Value: -1}} } for _, prop := range indexValues[1:] { @@ -114,9 +114,9 @@ func (d *Database) IndexEnsure(cfg interface{}, document interface{}) error { } if compoundValue[0] == '-' { - index[compoundValue[1:]] = -1 + index = append(index, primitive.E{compoundValue[1:], -1}) } else { - index[compoundValue] = 1 + index = append(index, primitive.E{compoundValue, 1}) } default: