From d0f9096e8e8a0a664ed0edd7d1f302eb435c7d11 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Mon, 15 Nov 2021 23:07:19 -0800 Subject: db: make replace an upsert --- db/mongodb/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/mongodb/client.go b/db/mongodb/client.go index 963860e..e6e9f0b 100644 --- a/db/mongodb/client.go +++ b/db/mongodb/client.go @@ -93,7 +93,9 @@ func (m *Mongo) InsertOne(ctx context.Context, cn string, in interface{}) error } func (m *Mongo) ReplaceOneById(ctx context.Context, cn string, id string, in interface{}) error { - if _, err := m.db.Collection(cn).ReplaceOne(ctx, bson.M{"_id": id}, in); err != nil { + tp := true + opts := &options.ReplaceOptions{Upsert: &tp} + if _, err := m.db.Collection(cn).ReplaceOne(ctx, bson.M{"_id": id}, in, opts); err != nil { return err } -- cgit v1.2.3