diff --git a/mongo.go b/mongo.go index d22e51d..cbf5dea 100644 --- a/mongo.go +++ b/mongo.go @@ -456,7 +456,7 @@ IndexSearchLabel: return err } -func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[string]bson.D, option *options.IndexOptions) error { +func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error { collection := mc.Collection(coll) cursor, err := collection.Indexes().List(context.Background(), options.ListIndexes().SetMaxTime(time.Second)) if err != nil { @@ -484,12 +484,12 @@ func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[str if len(v) == 1 { mod = mongo.IndexModel{ Keys: primitive.M{v[0].Key: v[0].Value}, - Options: options.MergeIndexOptions(options.Index().SetName(name), option), + Options: options.MergeIndexOptions(append(opts, options.Index().SetName(name))...), } } else { mod = mongo.IndexModel{ Keys: indices[name], - Options: options.MergeIndexOptions(options.Index().SetName(name), option), + Options: options.MergeIndexOptions(append(opts, options.Index().SetName(name))...), } } @@ -502,10 +502,10 @@ func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[str return nil } -func (mc MongoClient) MakeUniqueIndices(coll CollectionName, indices map[string]bson.D) error { - return mc.makeIndicesWithOption(coll, indices, options.Index().SetUnique(true)) +func (mc MongoClient) MakeUniqueIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error { + return mc.makeIndicesWithOption(coll, indices, append(opts, options.Index().SetUnique(true))...) } -func (mc MongoClient) MakeIndices(coll CollectionName, indices map[string]bson.D) error { - return mc.makeIndicesWithOption(coll, indices, options.Index()) +func (mc MongoClient) MakeIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error { + return mc.makeIndicesWithOption(coll, indices, opts...) }