github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/testutil/indexes.go (about) 1 package testutil 2 3 import ( 4 "github.com/evergreen-ci/evergreen/db" 5 "gopkg.in/mgo.v2" 6 ) 7 8 // AddTestIndexes drops and adds indexes for a given collection 9 func AddTestIndexes(collection string, unique, sparse bool, key ...string) error { 10 db.DropIndex(collection, key...) 11 err := db.EnsureIndex(collection, mgo.Index{ 12 Key: key, 13 Unique: unique, 14 Sparse: sparse, 15 }) 16 return err 17 }