diff options
author | Mike Crute <mike@crute.us> | 2021-11-15 23:07:19 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2021-11-15 23:07:19 -0800 |
commit | d0f9096e8e8a0a664ed0edd7d1f302eb435c7d11 (patch) | |
tree | c438b1a82d3a9a86bdb47503617777b4e55ff6cb | |
parent | 27b83d68d1419eed174e87de39a1351cd21d0375 (diff) | |
download | golib-db/mongodb/v0.2.0.tar.bz2 golib-db/mongodb/v0.2.0.tar.xz golib-db/mongodb/v0.2.0.zip |
db: make replace an upsertdb/mongodb/v0.2.0
-rw-r--r-- | db/mongodb/client.go | 4 |
1 files changed, 3 insertions, 1 deletions
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 | |||
93 | } | 93 | } |
94 | 94 | ||
95 | func (m *Mongo) ReplaceOneById(ctx context.Context, cn string, id string, in interface{}) error { | 95 | func (m *Mongo) ReplaceOneById(ctx context.Context, cn string, id string, in interface{}) error { |
96 | if _, err := m.db.Collection(cn).ReplaceOne(ctx, bson.M{"_id": id}, in); err != nil { | 96 | tp := true |
97 | opts := &options.ReplaceOptions{Upsert: &tp} | ||
98 | if _, err := m.db.Collection(cn).ReplaceOne(ctx, bson.M{"_id": id}, in, opts); err != nil { | ||
97 | return err | 99 | return err |
98 | } | 100 | } |
99 | 101 | ||