Hi team!
I’m using the Go SDK for couchbase, and I have a JSON to append to a map (an existing document ) in couchbase using N1QL. Here’s how the JSON is derrived in the Go program:
sampleData := struct{
ID string `json:"_id"`
Amount int `json:"amount"`
}{
"some_random_id",
700
}
// converting Go struct to JSON
b, _ := json.Marshal(sampleData)
// using it in query
updoc := gocb.NewN1qlQuery("UPDATE bucket SET field = ARRAY_APPEND(field, $1) WHERE type = 'mytype' ")
_, err = Bucket.ExecuteN1qlQuery(updoc, []interface{}{string(b)})
The UPDATE query works, but when I checked the data in couchbase, I found out the JSON was escaped, the format is as this:
// the doc returned from couchbase-server
{
"field":[
"{\"_id\":\"some_random_id\"}"
]
}
Any reason why its doing that? Cause I can’t Unmarshal it back to a struct when fetching again from the database.