Account for strings when reading from db 13/76013/1
authorKiran Kamineni <kiran.k.kamineni@intel.com>
Fri, 18 Jan 2019 20:52:47 +0000 (12:52 -0800)
committerKiran Kamineni <kiran.k.kamineni@intel.com>
Fri, 18 Jan 2019 20:52:50 +0000 (12:52 -0800)
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 <kiran.k.kamineni@intel.com>
src/k8splugin/db/mongo.go

index 65e721c..05976b1 100644 (file)
@@ -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