DropIndex 추가

This commit is contained in:
2023-08-23 17:40:14 +09:00
parent 2addec5adf
commit c34045e215

View File

@ -124,6 +124,18 @@ func (mc MongoClient) Close() {
}
}
func (mc MongoClient) DropIndex(coll CollectionName, name string) error {
matchcoll := mc.Collection(coll)
_, err := matchcoll.Indexes().DropOne(context.Background(), name)
if commanderr, ok := err.(mongo.CommandError); ok {
if commanderr.Code == 27 {
// 인덱스가 없는 것이므로 그냥 성공
return nil
}
}
return err
}
func (mc MongoClient) Watch(coll CollectionName, pipeline mongo.Pipeline, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error) {
if len(opts) == 0 {
opts = []*options.ChangeStreamOptions{options.ChangeStream().SetFullDocument(options.UpdateLookup).SetMaxAwaitTime(0)}