From bf089314f09085b0e9375694af010d1bb991b642 Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Thu, 7 Feb 2019 23:38:43 +0100 Subject: [PATCH] Use delete by id if target is provided --- mongox/common/deleteone.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mongox/common/deleteone.go b/mongox/common/deleteone.go index 8f72c8e..3b6c068 100644 --- a/mongox/common/deleteone.go +++ b/mongox/common/deleteone.go @@ -21,6 +21,10 @@ func DeleteOne(db *mongox.Database, target interface{}, filters ...interface{}) opts.Sort = composed.Sorter() + if target != nil { + composed.And(primitive.M{"_id": base.GetID(target)}) + } + if protected != nil { if protected.X.IsZero() { composed.And(primitive.M{"_x": primitive.M{"$exists": false}})