UPDATE default AS d
SET u.deptEmpCount = 12 FOR u IN d.UserList WHEN u.empID = 31 END,
u.deptId = 2 FOR u IN d.UserList WHEN u.empID = 31 END
WHERE ...;
UPDATE default AS d
SET d.UserList = ARRAY u I FOR u IN d.UserList WHEN u.empID = 31 END
WHERE ...;
deptEmpCount & deptId are inside userDept object?how to update deptEmpCount & deptId based on empID
want to add new User object to UserList in the existing doc:
{
“userAge”: 34,
“empID”: 33,
“empSal”: 120000,
“userDept”: {
“deptId”: 1,
“deptEmpCount”: 10,
“deptNo”: 3
}
}
UPDATE default AS d
SET u.userDept = {"deptId":1,"deptEmpCount: 10, deptNo:3} FOR u IN d.UserList WHEN u.empID = 33 END
WHERE ...;
To Add new object to UserList
UPDATE default AS d
SET d.UserList = ARRAY_APPEND(d.UserList, { "userAge": 34, "empID": 33, "empSal": 120000, "userDept": { "deptId": 1, "deptEmpCount": 10, "deptNo": 3 } })
WHERE ..
To Add new object to UserList if not there, if there update it.
UPDATE default d
SET d.UserList = (CASE WHEN (FIRST u FOR u IN d.UserList WHEN u.empID = 33 END) IS MISSING
THEN ARRAY_APPEND(d.UserList,
{ "userAge": 34, "empID": 33, "empSal": 120000, "userDept": { "deptId": 1, "deptEmpCount": 10, "deptNo": 3 } })
ELSE d.UserList END
END),
u.userDept.deptId = 2 FOR u IN d.UserList WHEN u.empID = 33 END
WHERE ....
suppose need to update empID,empSal like
batch update query
UPDATE default SET g.userAge = 332,g.empSal=12 FOR g IN UserList WHEN g.empID = 32 END
UPDATE default SET g.userAge = 332,g.empSal=12 FOR g IN UserList WHEN g.empID = 31 END
batch delete query
UPDATE default SET groupList = ARRAY g FOR g IN groupList WHEN v.groupID != 32 END
UPDATE default SET groupList = ARRAY g FOR g IN groupList WHEN v.groupID != 31 END
how to execute these queries in batch in one request.
UPDATE pocdata SET UserList[pos] = OBJECT_CONCAT(u, {"userAge":332, "empSal":12}) FOR pos:u IN UserList WHEN u.empID IN [31,32] END,
groupList = ARRAY g FOR g IN groupList WHEN g.groupID NOT IN [31, 32] END;
OR
UPDATE pocdata SET UserList[pos] = OBJECT_PUT(OBJECT_PUT(u, "userAge", 332), "empSal", 12) FOR pos:u IN UserList WHEN u.empID IN [31,32] END,
groupList = ARRAY g FOR g IN groupList WHEN g.groupID NOT IN [31, 32] END;
OR
UPDATE pocdata SET u.userAge = 332 FOR u IN UserList WHEN u.empID IN [31,32] END,
u.empSal = 12 FOR u IN UserList WHEN u.empID IN [31,32] END,
groupList = ARRAY g FOR g IN groupList WHEN g.groupID NOT IN [31, 32] END;
UPDATE default SET g.userAge = 331,g.empSal=11 FOR g IN UserList WHEN g.empID = 32 END
UPDATE default SET g.userAge = 332,g.empSal=12 FOR g IN UserList WHEN g.empID = 31 END
batch update where userAge and empSal value will be different for different empID .
UPDATE pocdata SET UserList[pos] = OBJECT_PUT(OBJECT_PUT(u, "userAge", 331), "empSal", 11) FOR pos:u IN UserList WHEN u.empID = 32 END,
UserList[pos] = OBJECT_PUT(OBJECT_PUT(u, "userAge", 332), "empSal", 12) FOR pos:u IN UserList WHEN u.empID = 31 END,
groupList = ARRAY g FOR g IN groupList WHEN g.groupID NOT IN [31, 32] END;
If so complex, you can get document in application and modify and write back using SDKs
Each SQL statement is independent there are no batches. Only SELECT can have subqueries.