goext/wmo/queryInsert.go

18 lines
359 B
Go
Raw Normal View History

2023-06-06 21:33:49 +02:00
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
}
2023-06-10 16:22:14 +02:00
mongoRes := c.coll.FindOne(ctx, bson.M{"_id": insRes.InsertedID})
2023-06-06 21:33:49 +02:00
2023-06-10 16:22:14 +02:00
return c.decodeSingle(ctx, mongoRes)
2023-06-06 21:33:49 +02:00
}