24 lines
624 B
Go
24 lines
624 B
Go
package wmo
|
|
|
|
import (
|
|
"context"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
|
)
|
|
|
|
func (c *Coll[TData]) InsertOne(ctx context.Context, valueIn TData) (TData, error) {
|
|
insRes, err := c.coll.InsertOne(ctx, valueIn)
|
|
if err != nil {
|
|
return *new(TData), err
|
|
}
|
|
|
|
mongoRes := c.coll.FindOne(ctx, bson.M{"_id": insRes.InsertedID})
|
|
|
|
return c.decodeSingle(ctx, mongoRes)
|
|
}
|
|
|
|
func (c *Coll[TData]) InsertMany(ctx context.Context, valueIn []TData) (*mongo.InsertManyResult, error) {
|
|
return c.coll.InsertMany(ctx, langext.ArrayToInterface(valueIn))
|
|
}
|