I should not update the old data, new data should have new key, and I should edit the new key with the old one and delete the old one. I need to do with that way.
Not sure why you can’t do update. How do u differentiate old and new document so that you can delete old documents.
You can use INSERT INTO SELECT and then DELETE .
INSERT INTO default VALUES("k0001", { "_class": "com.commencis.appconnect.adminpanel.data.entity.ScreenNamesMappingEntity", "id": "whitelabel::WEB::screenNamesMapping", "mappings": { "/": "Ana sayfa" } });
INSERT INTO default (KEY t.id, value t)
SELECT OBJECT_PUT(t,"mappings",OBJECT_PUT(t.mappings,"/",{"viewLabel":t.mappings.`/`})) AS t
FROM default AS t
WHERE _class ="com.commencis.appconnect.adminpanel.data.entity.ScreenNamesMappingEntity";
DELETE FROM default AS d
WHERE d._class ="com.commencis.appconnect.adminpanel.data.entity.ScreenNamesMappingEntity"
AND d.mappings.`/`.viewLabel IS MISSING;
the values of “/” and :“Ana sayfa” and also platform changes, it should do automatically Sorry I am new, but I 'll do try to understand but a little help would awesome for me.
“/” must be constant and value can be vary. If not give full example.
If mappings has field “/”: val it coverts into “/”: { “viewLabel”: val } irrespective of platform for all documents.
Do you want convert multiple fields of mappigns or all mappings this new format? If yes give a example.
So I said I can not update but well I can now. I am trying this now updating old document. Like above example I can have multiple key and its values, so I want do it dynamically. I need to get key, add viewLabel attribute to its value and keep going. It is hard to understand for me to write N1QL
N1QL works same as SQL, Data representation is in objects and it has additional data types arrays.
INSERT INTO default VALUES("k0001", { "_class": "com.commencis.appconnect.adminpanel.data.entity.ScreenNamesMappingEntity", "id": "whitelabel::WEB::screenNamesMapping", "mappings": { "/": "Ana sayfa", "/career/": "Kariyer", "/company/": "Şirket Hakkında", "/products/": "Ürünler" } });
UPDATE default AS d SET
d.mappings = OBJECT v.name: {"viewLabel":v.val} FOR v IN OBJECT_PAIRS(d.mappings) END
WHERE d._class ="com.commencis.appconnect.adminpanel.data.entity.ScreenNamesMappingEntity"
AND d.mappings IS NOT MISSING;