Skip to content

Commit 18a7424

Browse files
authored
Merge pull request #203 from withchao/main
feat: add InsertOne
2 parents e01000d + 9bebe5d commit 18a7424

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

db/mongoutil/util.go

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ func findOptionToCountOption(opts []*options.FindOptions) *options.CountOptions
4747
return options.Count()
4848
}
4949

50+
func InsertOne[T any](ctx context.Context, coll *mongo.Collection, val T, opts ...*options.InsertOneOptions) error {
51+
_, err := coll.InsertOne(ctx, val, opts...)
52+
if err != nil {
53+
return errs.WrapMsg(err, "mongo insert one")
54+
}
55+
return nil
56+
}
57+
5058
func InsertMany[T any](ctx context.Context, coll *mongo.Collection, val []T, opts ...*options.InsertManyOptions) error {
5159
_, err := coll.InsertMany(ctx, anes(val), opts...)
5260
if err != nil {

0 commit comments

Comments
 (0)