Skip to content

Commit

Permalink
update updateMany func
Browse files Browse the repository at this point in the history
  • Loading branch information
phuong committed Jun 15, 2022
1 parent 4379029 commit e81bac3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/mopertest/aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestAggregation(t *testing.T) {

if int(result[0]["total"].(int32)) != expect {
t.Error("wrong result", result[0]["total"], expect)
return
}
}

Expand Down
20 changes: 20 additions & 0 deletions mocom/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mocom

import (
"context"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func AddIndex[T Model](ctx context.Context, index mongo.IndexModel, opts ...*options.CreateIndexesOptions) (string, error) {
var t T
col := collWrite(t.CollName())
return col.Indexes().CreateOne(ctx, index, opts...)
}

func AddIndexes[T Model](ctx context.Context, indexes []mongo.IndexModel, opts ...*options.CreateIndexesOptions) ([]string, error) {
var t T
col := collWrite(t.CollName())
return col.Indexes().CreateMany(ctx, indexes, opts...)
}
4 changes: 2 additions & 2 deletions mocom/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func UpdateAndReturn[T Model](ctx context.Context, filter interface{}, update in
return
}

func UpdateMany[T Model](ctx context.Context, filter interface{}, update interface{}) (*mongo.UpdateResult, error) {
func UpdateMany[T Model](ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) {
var t T
return collWrite(t.CollName()).UpdateMany(ctx, filter, update)
return collWrite(t.CollName()).UpdateMany(ctx, filter, update, opts...)
}

0 comments on commit e81bac3

Please sign in to comment.