summaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/infra/db/mongo.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/pkg/infra/db/mongo.go')
-rw-r--r--src/orchestrator/pkg/infra/db/mongo.go31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/orchestrator/pkg/infra/db/mongo.go b/src/orchestrator/pkg/infra/db/mongo.go
index b33d6c65..a3fdc570 100644
--- a/src/orchestrator/pkg/infra/db/mongo.go
+++ b/src/orchestrator/pkg/infra/db/mongo.go
@@ -539,9 +539,6 @@ func (m *MongoStore) Find(coll string, key Key, tag string) ([][]byte, error) {
}
result = append(result, data)
}
- if len(result) == 0 {
- return result, pkgerrors.Errorf("Did not find any objects with tag: %s", tag)
- }
return result, nil
}
@@ -587,3 +584,31 @@ func (m *MongoStore) Remove(coll string, key Key) error {
}
return nil
}
+
+// RemoveTag is used to remove an element from a document
+func (m *MongoStore) RemoveTag(coll string, key Key, tag string) error {
+ c := getCollection(coll, m)
+ ctx := context.Background()
+
+ filter, err := m.findFilter(key)
+ if err != nil {
+ return err
+ }
+
+ _, err = decodeBytes(
+ c.FindOneAndUpdate(
+ ctx,
+ filter,
+ bson.D{
+ {"$unset", bson.D{
+ {tag, ""},
+ }},
+ },
+ options.FindOneAndUpdate().SetUpsert(true).SetReturnDocument(options.After)))
+
+ if err != nil {
+ return pkgerrors.Errorf("Error removing tag: %s", err.Error())
+ }
+
+ return nil
+}