Using Couchbase Server, 6.6…
How can I add a new sub-array to a document that is based loosely on an existing array?
Given a document such as the following that already has an ‘asdf’ array property,
[
{
"beer-sample": {
"abv": 9.8,
"asdf": [
"hello",
"goodbye"
],
"brewery_id": "21st_amendment_brewery_cafe",
"category": "North American Ale",
"description": "Deep, golden,...in Hayward, California.",
"ibu": 0,
"name": "Double Trouble IPA",
"srm": 0,
"style": "Imperial or Double India Pale Ale",
"type": "beer",
"upc": 0,
"updated": "2010-07-22 20:00:20"
}
}
]
… how can I get the same document but with the added ‘asdf2’ array?
[
{
"beer-sample": {
"abv": 9.8,
"asdf": [
"hello",
"goodbye"
],
"asdf2": [
"hello all!",
"goodbye all!"
],
"brewery_id": "21st_amendment_brewery_cafe",
"category": "North American Ale",
"description": "Deep, golden,...in Hayward, California.",
"ibu": 0,
"name": "Double Trouble IPA",
"srm": 0,
"style": "Imperial or Double India Pale Ale",
"type": "beer",
"upc": 0,
"updated": "2010-07-22 20:00:20"
}
}
]
I have tried the following, but it gives me an sub-document with an extra layer.
UPDATE `beer-sample` bs1
SET bs1.asdf2 = (
SELECT ARRAY var1 || ' all!' FOR var1 IN bs2.asdf END AS anExtraLayer
FROM `beer-sample` bs2
WHERE META().id = "21st_amendment_brewery_cafe-double_trouble_ipa")
WHERE META().id = "21st_amendment_brewery_cafe-double_trouble_ipa"