diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/mongodb/client.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/db/mongodb/client.go b/db/mongodb/client.go index 98369b9..82082fc 100644 --- a/db/mongodb/client.go +++ b/db/mongodb/client.go | |||
@@ -2,6 +2,7 @@ package mongodb | |||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | "fmt" | ||
5 | "net/url" | 6 | "net/url" |
6 | 7 | ||
7 | "go.mongodb.org/mongo-driver/bson" | 8 | "go.mongodb.org/mongo-driver/bson" |
@@ -88,3 +89,16 @@ func (m *Mongo) ReplaceOneById(ctx context.Context, cn string, id string, in int | |||
88 | 89 | ||
89 | return nil | 90 | return nil |
90 | } | 91 | } |
92 | |||
93 | func (m *Mongo) DeleteOneById(ctx context.Context, cn string, id string) error { | ||
94 | dr, err := m.db.Collection(cn).DeleteOne(ctx, bson.M{"_id": id}) | ||
95 | if err != nil { | ||
96 | return err | ||
97 | } | ||
98 | |||
99 | if dr.DeletedCount != 1 { | ||
100 | return fmt.Errorf("Invalid deletion record count %d not 1", dr.DeletedCount) | ||
101 | } | ||
102 | |||
103 | return nil | ||
104 | } | ||