From 4bfbc6d3fb1cb11ac2a409764a1380d1741f2af1 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Fri, 18 Jan 2019 12:52:47 -0800 Subject: Account for strings when reading from db Strings are not returned unmodified by the mongo driver and seem to have a size value prepended to them. Using the built in string reader resolves this issue. Issue-ID: MULTICLOUD-441 Change-Id: I5c5e35b0749a61b741c9b63cfad55bf2720d91bb Signed-off-by: Kiran Kamineni --- src/k8splugin/db/mongo.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/k8splugin/db/mongo.go b/src/k8splugin/db/mongo.go index 65e721c3..05976b12 100644 --- a/src/k8splugin/db/mongo.go +++ b/src/k8splugin/db/mongo.go @@ -183,7 +183,13 @@ func (m *MongoStore) Read(coll, key, tag string) ([]byte, error) { } //Return the data as a byte array - return tagdata.Lookup(tag).Value, nil + //Convert string data to byte array using the built-in functions + switch tagdata.Lookup(tag).Type { + case bson.TypeString: + return []byte(tagdata.Lookup(tag).StringValue()), nil + default: + return tagdata.Lookup(tag).Value, nil + } } // Helper function that deletes an object by its ID -- cgit 1.2.3-korg