23 lines
407 B
Go
23 lines
407 B
Go
package wmo
|
|
|
|
import (
|
|
"context"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
var res TData
|
|
|
|
err = c.coll.FindOne(ctx, bson.M{"_id": insRes.InsertedID}).Decode(&res)
|
|
if err != nil {
|
|
return *new(TData), err
|
|
}
|
|
|
|
return res, nil
|
|
}
|