A long story about why, but we need to be able to store a freeform document a user provides.
I take a payload and I store it in a database using a Key/Value approach. e.g.
// GlobalKeypair represents a single entry in the globals DB
type GlobalKeypair struct {
Key string `json:"key" bson:"key"`
Value interface{} `json:"value" bson:"value"`
}
filter := bson.M{"key": key}
kp := GlobalKeypair{
Key: key,
Value: value,
}
info, err := coll.ReplaceOne(
context.Background(), filter, kp, options.Replace().SetUpsert(true))
The issue is when it comes back out of the database, it’s getting garbled. I’m thinking due to the freeform nature of the interface.
So I store this:
GlobalKeypair{Key: "some-key",
Value: map[string]interface{}{
"lid-brain-test-1": map[string]interface{}{
"brain": "StreamingBrain",
"floor": 0.65,
},
"lid-brain-test-2": map[string]interface{}{
"brain": "BulkBrain",
"floor": 0.65,
},
}
}
And when I pull it out, I get this:
"some-key": [
{
"Key": "lid-brain-test-1",
"Value": [
{
"Key": "brain",
"Value": "StreamingBrain"
},
{
"Key": "floor",
"Value": 0.65
}
]
},
{
"Key": "lid-brain-test-2",
"Value": [
{
"Key": "brain",
"Value": "BulkBrain"
},
{
"Key": "floor",
"Value": 0.65
}
]
}
],
I think something is happening under the covers where it’s structuring my interface into a bson.E, but I’m at the end of my rope. I can’t figure out what’s going on.