Adding bulk user into couchbase not working

Hi,
I am trying to add bulk user (object) into multiple groups with a loop. in a promise

But it is not working perfectly. It is missing some users and adding some.

Not able to find any reason??

e.g
{
“pg”: [
“name”:“pgroup1”,
{
“lg”: [
{
“name”: “localGroup1”,
“user”: [
{
“id”: “user1”,
}
]
},
{
“name”: “localGroup2”,
“users”: [
{
“id”: “user2”,
}
]
}

  ]
}
]

}

Want to add 2 more users in both the group. But it is but working as excepted.
couchbase version --4.6.2-3095 enterprise edition

sql— UPDATE app SET lg1.users = ARRAY_APPEND(lg1.users,$1)
FOR lg1 in pg.lg
FOR pg1 in pg
WHEN pg1.name = $2 AND lg1.name = $3
END
WHERE META(app).id = $4`

What is couchbase version and What is SQL statement you are using.

Want to add 2 more users in both the group. But it is but working as excepted.
couchbase version --4.6.2-3095 enterprise edition

sql— UPDATE app SET localUserGroup.users = ARRAY_APPEND(localUserGroup.users,$1)
FOR localUserGroup in policyGroup.localUserGroups
FOR policyGroup in policyGroups
WHEN policyGroup.name = $2 AND localUserGroup.name = $3
END
WHERE META(app).id = $4`

Qualifies only one localUseGroup , you have different names.
If need to add new users for all the user usergroups change to WHEN policyGroup.name = $2 END or make it OR/IN on both names (WHEN policyGroup.name = $2 AND localUserGroup.name IN $3 END, supply $3 as [“localGroup1”, “localGroup2”])
What are the query parameter values and what is expected updated document and what actually happening.

trying it in a loop of loping through lg

loop1–

UPDATE app SET lg1.users = ARRAY_APPEND(lg1.users,$1)
FOR lg1 in pg1.lg
FOR pg1 in pg
WHEN pg1.name = ‘pgroup1’ AND lg1.name = 'localGroup1’
END
WHERE META(app).id = ‘appid’`

loop2—
UPDATE app SET lg1.users = ARRAY_APPEND(lg1.users,$1)
FOR lg1 in pg1.lg
FOR pg1 in pg
WHEN pg1.name = ‘pgroup1’ AND lg1.name = 'localGroup2’
END
WHERE META(app).id = ‘appid’`

I have provided how to do through single update in my previous post. Are you still have issue.

UPDATE app  USE KEYS ["appid"] 
         SET lg1.users = ARRAY_APPEND(lg1.users,$1)
                FOR lg1 IN pg1.lg
                      FOR pg1 IN pg  
                WHEN pg1.name = "pgroup1" AND lg1.name IN ["localGroup1", "localGroup2"] END;

Actually we are reusing the single user add query in a loop…which is failing… for some users …
.

It should work. If still fails Provide the example with data .