Search code examples
xquerymarklogic

How to set the value of one field to another filed in using XQuery


Very new to XQuery and MarkLogic, what is the XQuery version of the following statement?

update all_the_records 
set B_field = A_field 
where B_field is null and A_field is not null

Solution

  • Something like this might get you started. But remember that you're working with trees, not tables. Things are generally more complicated because of that extra dimension.

    for $doc in collection()/doc[not(b)][a]
    let $a as element() := $doc/a
    return xdmp:node-insert-child($doc, element b { $a/@*, $a/node() })