Create dynamic nested map[string]interface{}

Hi to all

I need to build dinamyc mongoDB update query based on request body payload.

Source Code Example

What i need to do is create a map[string]map[string]interface{}
with different values for same key without overriding, how i can do?

The code in your Play is quite complex. Can you trim it down to a Short, Self Contained, Correct (Compilable), Example? This will make it easier for us to help you.

Updated example with trimmed body request

Hi, Gabriele,

When you’re looping over the keys in the m map in PrepareBsonM, you’re creating new maps and overwriting previous ones you set in your set map under the "$set" key, this way, only the last one “wins.”

Is PrepareBsonM's output supposed to look like query?

Hi @skillian Yes the output of PrepareBsonM should look like query.
How i can achieve the desired output?

How i can achieve the desired output?

i have tried to create a slice of interface


But doesen’t work it returns an error beacuse m[i] is an interface and not a slice of interface

Solved adding check to create nested map[string] only if not already created

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.