Reputation: 51
I am trying to update an array of strings into an array of objects in Couchbase using N1QL. I would like to take the following structure:
{
"id": 1,
"items": [
"one",
"two",
"three"
]
}
And transform it into:
{
"id": 1,
"items": [
{
"id": "some-uuid-001",
"value": "one"
},
{
"id": "some-uuid-002",
"value": "two"
},
{
"id": "some-uuid-003",
"value": "three"
}
]
}
I am on Couchbase 4.6 and would like to use N1QL only.
Upvotes: 1
Views: 736
Reputation: 51
Answered my own question:
update bucket
set bucket.items[i] = {"id": UUID(), "value": bucket.items[i]}
FOR i:sb IN bucket.items END
where id = 1;
Upvotes: 1