1 Commits

Author SHA1 Message Date
Nikita Tokarchuk fd53c66690 Use ordered document for index model 2020-03-25 17:40:26 +01:00
+4 -4
View File
@@ -64,15 +64,15 @@ func (d *Database) IndexEnsure(cfg interface{}, document interface{}) error {
panic(fmt.Errorf("cannot evaluate index key")) panic(fmt.Errorf("cannot evaluate index key"))
} }
index := primitive.M{key: 1}
opts := &options.IndexOptions{ opts := &options.IndexOptions{
Background: &f, Background: &f,
Unique: &f, Unique: &f,
Name: &name, Name: &name,
} }
index := primitive.D{{Key: key, Value: 1}}
if indexValues[0] == "-" { if indexValues[0] == "-" {
index[key] = -1 index = primitive.D{{Key: key, Value: -1}}
} }
for _, prop := range indexValues[1:] { for _, prop := range indexValues[1:] {
@@ -114,9 +114,9 @@ func (d *Database) IndexEnsure(cfg interface{}, document interface{}) error {
} }
if compoundValue[0] == '-' { if compoundValue[0] == '-' {
index[compoundValue[1:]] = -1 index = append(index, primitive.E{compoundValue[1:], -1})
} else { } else {
index[compoundValue] = 1 index = append(index, primitive.E{compoundValue, 1})
} }
default: default: