aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2021-11-15 23:07:19 -0800
committerMike Crute <mike@crute.us>2021-11-15 23:07:19 -0800
commitd0f9096e8e8a0a664ed0edd7d1f302eb435c7d11 (patch)
treec438b1a82d3a9a86bdb47503617777b4e55ff6cb
parent27b83d68d1419eed174e87de39a1351cd21d0375 (diff)
downloadgolib-d0f9096e8e8a0a664ed0edd7d1f302eb435c7d11.tar.bz2
golib-d0f9096e8e8a0a664ed0edd7d1f302eb435c7d11.tar.xz
golib-d0f9096e8e8a0a664ed0edd7d1f302eb435c7d11.zip
db: make replace an upsertdb/mongodb/v0.2.0
-rw-r--r--db/mongodb/client.go4
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
95func (m *Mongo) ReplaceOneById(ctx context.Context, cn string, id string, in interface{}) error { 95func (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