oc-lib/dbs/dbs.go

23 lines
410 B
Go
Raw Normal View History

2024-07-18 11:51:12 +02:00
package dbs
import (
"go.mongodb.org/mongo-driver/bson"
)
type Input = map[string]interface{}
func InputToBson(i Input, isUpdate bool) bson.D {
input := bson.D{}
for k, v := range i {
if k == "id" {
input = append(input, bson.E{Key: "_id", Value: v})
} else {
input = append(input, bson.E{Key: k, Value: v})
}
}
if isUpdate {
return bson.D{{Key: "$set", Value: input}}
}
return input
}