Update operations on JSON objects are not working

Sunday, 12 November 2017 · 3 messages · last reply 13 Nov 2017
EJ
E. Wray Johnson12 Nov 2017 07:12 #
I have tried many ways of updating JSON objects and none seem to work. Using the BaseX GUI, the Result window seems to show the correct outcom, but the database is not modified. What am I missing? Do I need to explicitly start/stop a transaction? XQUERY: db:open('db','country')/json[countryId = 1] update { replace value of node countryName with 'Aldorria', insert node <population type="number">1000</population> into . } Result:
<json type="object">
  <countryId type="number">1</countryId >
  <countryName>Aldorria</countryName>
  <population type="number">1234</population>
  <planetName>Zeldon</planetName>
</json>
CG
Christian Grün13 Nov 2017 23:35 #
The update keyword is a so-called “non-updating expression”; the result will not have any effect on the database. You can use the simple map operator… db:open('db','country')/json[countryId = 1] ! ( replace value of node countryName with 'Aldorria', insert node <population type="number">1000</population> into . ) …or FLWOR expressions, etc. to change nodes in the database. See e.g. [1] to learn more about XQuery Update. ___________________________ [1] http://docs.basex.org/wiki/XQuery_Update
Quoted text · E. Wray Johnson · 21 lines
On Sun, Nov 12, 2017 at 6:12 AM, E. Wray Johnson <wray.johnson at gmail.com> wrote: > I have tried many ways of updating JSON objects and none seem to work. > Using the BaseX GUI, the Result window seems to show the correct outcom, but > the database is not modified. What am I missing? Do I need to explicitly > start/stop a transaction? > > XQUERY: > db:open('db','country')/json[countryId = 1] > update { > replace value of node countryName with 'Aldorria', > insert node <population type="number">1000</population> into . > } > > > Result: > <json type="object"> > <countryId type="number">1</countryId > > <countryName>Aldorria</countryName> > <population type="number">1234</population> > <planetName>Zeldon</planetName> > </json>
EJ
E. Wray Johnson13 Nov 2017 23:37 #
Thanks. I figured out what I was doing wrong.
Quoted text · Christian Grün · 43 lines
On Mon, Nov 13, 2017 at 5:36 PM Christian Grün <christian.gruen at gmail.com> wrote: > The update keyword is a so-called “non-updating expression”; the > result will not have any effect on the database. You can use the > simple map operator… > > db:open('db','country')/json[countryId = 1] ! ( > replace value of node countryName with 'Aldorria', > insert node <population type="number">1000</population> into . > ) > > …or FLWOR expressions, etc. to change nodes in the database. > > See e.g. [1] to learn more about XQuery Update. > ___________________________ > > [1] http://docs.basex.org/wiki/XQuery_Update > > > On Sun, Nov 12, 2017 at 6:12 AM, E. Wray Johnson <wray.johnson at gmail.com> > wrote: > > I have tried many ways of updating JSON objects and none seem to work. > > Using the BaseX GUI, the Result window seems to show the correct outcom, > but > > the database is not modified. What am I missing? Do I need to explicitly > > start/stop a transaction? > > > > XQUERY: > > db:open('db','country')/json[countryId = 1] > > update { > > replace value of node countryName with 'Aldorria', > > insert node <population type="number">1000</population> into . > > } > > > > > > Result: > > <json type="object"> > > <countryId type="number">1</countryId > > > <countryName>Aldorria</countryName> > > <population type="number">1234</population> > > <planetName>Zeldon</planetName> > > </json> >

⚡Generated with XQuery