인덱스 옵션 인자로 받음
This commit is contained in:
14
mongo.go
14
mongo.go
@ -456,7 +456,7 @@ IndexSearchLabel:
|
|||||||
return err
|
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)
|
collection := mc.Collection(coll)
|
||||||
cursor, err := collection.Indexes().List(context.Background(), options.ListIndexes().SetMaxTime(time.Second))
|
cursor, err := collection.Indexes().List(context.Background(), options.ListIndexes().SetMaxTime(time.Second))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -484,12 +484,12 @@ func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[str
|
|||||||
if len(v) == 1 {
|
if len(v) == 1 {
|
||||||
mod = mongo.IndexModel{
|
mod = mongo.IndexModel{
|
||||||
Keys: primitive.M{v[0].Key: v[0].Value},
|
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 {
|
} else {
|
||||||
mod = mongo.IndexModel{
|
mod = mongo.IndexModel{
|
||||||
Keys: indices[name],
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc MongoClient) MakeUniqueIndices(coll CollectionName, indices map[string]bson.D) error {
|
func (mc MongoClient) MakeUniqueIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||||
return mc.makeIndicesWithOption(coll, indices, options.Index().SetUnique(true))
|
return mc.makeIndicesWithOption(coll, indices, append(opts, options.Index().SetUnique(true))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc MongoClient) MakeIndices(coll CollectionName, indices map[string]bson.D) error {
|
func (mc MongoClient) MakeIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||||
return mc.makeIndicesWithOption(coll, indices, options.Index())
|
return mc.makeIndicesWithOption(coll, indices, opts...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user