-
Notifications
You must be signed in to change notification settings - Fork 45
/
2_sample_index_test.go
32 lines (27 loc) · 776 Bytes
/
2_sample_index_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build integration
package migrate
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const globalTestIndexName = "test_idx_2"
func init() {
MustRegister(func(ctx context.Context, db *mongo.Database) error {
keys := bson.D{{"a", 1}}
opt := options.Index().SetName(globalTestIndexName)
model := mongo.IndexModel{Keys: keys, Options: opt}
_, err := db.Collection(globalTestCollection).Indexes().CreateOne(ctx, model)
if err != nil {
return err
}
return nil
}, func(ctx context.Context, db *mongo.Database) error {
_, err := db.Collection(globalTestCollection).Indexes().DropOne(ctx, globalTestIndexName)
if err != nil {
return err
}
return nil
})
}