From: <basex-talk-boun...@mailman.uni-konstanz.de> on behalf of "E. Wray
Johnson" <wray.john...@gmail.com>
Date: Sunday, November 12, 2017 at 12:32 AM
To: BaseX <basex-talk@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 12 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