n1ql query to update multiple parameters in array of json data

我只是一个虾纸丫 提交于 2019-11-30 16:48:19

Each SET term is independent, so you can do the following:

UPDATE default
USE KEYS "userdetails"
SET a.firstname="abc" FOR a IN friends WHEN a.company="microsoft" END,
    a.lastname="xyz" FOR a IN friends WHEN a.company="microsoft" END
RETURNING friends;

To answer your comment, the following two forms avoid the double loop. You can measure with actual data to see which form gives the best performance.

UPDATE default
USE KEYS "userdetails"
SET friends[i] = {"firstname":"abc", "lastname":"xyz", "company":"microsoft"} FOR i : a IN friends WHEN a.company="microsoft" END
RETURNING friends;

UPDATE default
USE KEYS "userdetails"
SET friends[i] = OBJECT_PUT(OBJECT_PUT(a, "firstname", "abc"), "lastname", "xyz") FOR i : a IN friends WHEN a.company="microsoft" END
RETURNING friends;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!