How to update field in array with N1QL

n1ql

#1

Hello, i have json look like this
“host1”: {
“instances”: [
{
“capacity”: {
“change”: {
“rps”: 0,
“rt”: 1000
},
“max_connections”: 0,
“read”: {
“rps”: 0,
“rt”: 500
}
},
“conn_string”: “local”,
“state”: “enabled”
}
],
“quotas”: {
“activities”: {
“redirect”: {
“change”: 100,
“read”: 100
},
“lost”: {
“change”: 0,
“read”: 1
}
},
“users”: {
“default”: {
“change”: 0,
“max_connections”: 0,
“read”: 0
},
“admin”: {
“change”: 0,
“max_connections”: 1,
“read”: 1
}
}
}
},
“host2”: {
“instances”: [
{
“capacity”: {
“change”: {
“rps”: 0,
“rt”: 1000
},
“max_connections”: 0,
“read”: {
“rps”: 0,
“rt”: 500
}
},
“conn_string”: “local”,
“state”: “enabled”
}
],
“quotas”: {
“activities”: {
“redirect”: {
“change”: 100,
“read”: 100
},
“lost”: {
“change”: 0,
“read”: 1
}
},
“users”: {
“default”: {
“change”: 0,
“max_connections”: 0,
“read”: 0
},
“admin”: {
“change”: 0,
“max_connections”: 1,
“read”: 1
}
}
}
},

I want update filed conn_string : enabled in status conn_string: disabled. How to do it?
I have already helped How to make select: URL How to Select' field's in list N1QL
I tryed this query
UPDATE registry USE KEYS ‘source_ucp’ SET state = enabled WHERE state IN (SELECT op.name,opi.state FROM registry AS r USE KEYS “source_ucp” UNNEST OBJECT_PAIRS® AS op UNNEST op.val.instances AS opi WHERE op.name IN [“host1”,“host2”]);
Query dont work


#2
INSERT INTO default VALUES ("k001", { "host1": { "instances": [ { "capacity": { "change": { "rps": 0, "rt": 1000 }, "max_connections": 0, "read": { "rps": 0, "rt": 500 } }, "conn_string": "local", "state": "disabled" } ], "quotas": { "activities": { "redirect": { "change": 100, "read": 100 }, "lost": { "change": 0, "read": 1 } }, "users": { "default": { "change": 0, "max_connections": 0, "read": 0 }, "admin": { "change": 0, "max_connections": 1, "read": 1 } } } }, "host2": { "instances": [ { "capacity": { "change": { "rps": 0, "rt": 1000 }, "max_connections": 0, "read": { "rps": 0, "rt": 500 } }, "conn_string": "local", "state": "disabled" } ], "quotas": { "activities": { "redirect": { "change": 100, "read": 100 }, "lost": { "change": 0, "read": 1 } }, "users": { "default": { "change": 0, "max_connections": 0, "read": 0 }, "admin": { "change": 0, "max_connections": 1, "read": 1 } } } } });

UPDATE default AS r USE KEYS "k001"
SET opi.state = "enabled" FOR opi IN r.[op].instances FOR op IN OBJECT_NAMES(r)
                          WHEN op IN ["host1", "host2"] AND opi.state = "disabled" END
WHERE ANY op IN OBJECT_PAIRS(r)
      SATISFIES op.name IN ["host1", "host2"]
                AND (ANY opi IN op.val.instances
                     SATISFIES opi.state = "disabled"
                     END)
      END;