summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRitu Sood <Ritu.Sood@intel.com>2020-04-16 22:03:58 +0000
committerGerrit Code Review <gerrit@onap.org>2020-04-16 22:03:58 +0000
commitc898a84208d20f0040778450cc401a35c3f8ee41 (patch)
tree571091d751724e849066e577cc5bf4722b3e9c68
parent4ae60c1b50750587ab9d3960617a47d7db57b311 (diff)
parent9a0939c26080c08fa87193be9e55634615de0daa (diff)
Merge "Mongo api changes"
-rw-r--r--src/orchestrator/pkg/infra/db/mongo.go31
-rw-r--r--src/orchestrator/pkg/infra/db/store.go3
2 files changed, 31 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
+}
diff --git a/src/orchestrator/pkg/infra/db/store.go b/src/orchestrator/pkg/infra/db/store.go
index 9c6532f1..a332fcda 100644
--- a/src/orchestrator/pkg/infra/db/store.go
+++ b/src/orchestrator/pkg/infra/db/store.go
@@ -64,6 +64,9 @@ type Store interface {
// Remove all the document(s) matching the key
RemoveAll(coll string, key Key) error
+
+ // Remove the specifiec tag from the document matching the key
+ RemoveTag(coll string, key Key, tag string) error
}
// CreateDBClient creates the DB client