From 7e7d023252651c861a28f5a4da12f421f6a079f1 Mon Sep 17 00:00:00 2001 From: mountain Date: Sun, 26 Nov 2023 15:46:34 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B8=EB=8D=B1=EC=8A=A4=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=20=EC=9D=B8=EC=9E=90=EB=A1=9C=20=EB=B0=9B=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mongo.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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...) }