Can't update or delete JSON objects

Sunday, 12 November 2017 · 2 messages · last reply 13 Nov 2017
EJ
E. Wray Johnson12 Nov 2017 10:32 #
I have tried XQUERY updates that should work but they don't work. My technique of storing JSON documents is perhaps not traditional. I have reduced my example to this simple example. FRIST CREATE DATABASE WITH ONE DOCUMENT:
db:create('geography', json:parse('{ "code": "USA", "name": "United States
of America", "birth": 1776 }'), '/country')
THEN ADD ANOTHER DOCUMENT: db:add('geography', json:parse('{ "code": "CAN", "name": "Canada", "birth": 1867 }'), '/country') 1. How can I update either of these documents using 'code' as the unique identifier? 1. How can I change the 'name' or 'birth'? 2. How can I add a 'population' number? 2. How can I delete either of these documents using 'code' as the unique identifier?
KS
Kendall Shaw13 Nov 2017 20:19 #
Quoted text · E. Wray Johnson · 27 lines
From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of "E. Wray Johnson" <wray.johnson at gmail.com> Date: Sunday, November 12, 2017 at 12:32 AM To: BaseX <basex-talk at mailman.uni-konstanz.de> Subject: [basex-talk] Can't update or delete JSON objects I have tried XQUERY updates that should work but they don't work. My technique of storing JSON documents is perhaps not traditional. I have reduced my example to this simple example. FRIST CREATE DATABASE WITH ONE DOCUMENT: db:create('geography', json:parse('{ "code": "USA", "name": "United States of America", "birth": 1776 }'), '/country') THEN ADD ANOTHER DOCUMENT: db:add('geography', json:parse('{ "code": "CAN", "name": "Canada", "birth": 1867 }'), '/country') 1. How can I update either of these documents using 'code' as the unique identifier? * How can I change the 'name' or 'birth'? * How can I add a 'population' number? 1. How can I delete either of these documents using 'code' as the unique identifier? My knowledge xquery update has lots of gaps. But, here are some answers. Changing the value of the name element: replace value of node db:open('geography')/json[code='CAN]/name with 'Canadia, eh?' Adding a population number: insert node <population type="number">12</population> into db:open('geography')/json[code='USA'] Delete “document”: delete node db:open('geography')/json[code='XAN'] The update example you gave in the previous post is a BaseX extension and a non-updating expression. A very important concept about XQuery update is the notion of an updating expression. This has important information: http://docs.basex.org/wiki/XQuery_Update#Pending_Update_List Kendall

⚡Generated with XQuery