As far as I know, you have to differentiate between insert and replace
scenarios when using the xdmp:node-XXXX functions:
doc("/my-doc.json")/xdmp:node-insert-child(object-node(), object-node {
"PropName" : "PropValue" }/PropName)
doc("/my-doc.json")/xdmp:node-replace(PropName, object-node { "PropName" :
"PropValue" }/PropName)
If you try to reinsert a property with the same name, you will get an
exception. If you need insert-or-replace behavior, though, you could wrap the
xdmp:node-replace call in a try/catch and call xdmp:node-insert-child in the
catch block when the exception thrown is XDMP-CHILDDUPNAME.
-Will
> On Apr 1, 2016, at 7:13 AM, Kevin Leturc <[email protected]> wrote:
>
> Hi,
>
> I have stored documents in MarkLogic in JSON format, see this example below :
> {
> 'ecm__id': '00000000-0000-0000-0000-000000000000',
> 'ecm__racl': [ 'Administrator', 'Members' ],
> 'dc__modified': '1970-01-01T00:00:00.000'
> }
>
> I have two use cases:
> - replace-insert an object, for example { "ecm__minorVersion": 0 }
> - replace-insert an object with array, for example { "ecm__racl": [
> "Administrator", "members" ] }
>
> Currently the two use cases have the same kind of patch request. For example
> with the first one, I have this patch operation :
> {"pathlang":"xpath",
> "patch":[{"replace-insert":{"select":"/node('ecm__minorVersion')",
> "context":"/node('ecm__id')", "position":"after",
> "content":{"ecm__minorVersion":0}}}]}
>
> Then I get this document :
> {
> 'ecm__id': '00000000-0000-0000-0000-000000000000',
> 'ecm__minorVersion': 0,
> 'ecm__racl': [ 'Administrator', 'Members' ],
> 'dc__modified': '1970-01-01T00:00:00.000'
> }
>
> If I re-patch the same document with minor version = 1, I get :
> {
> 'ecm__id': '00000000-0000-0000-0000-000000000000',
> 'ecm__minorVersion': { 'ecm__minorVersion': 1 },
> 'ecm__racl': [ 'Administrator', 'Members' ],
> 'dc__modified': '1970-01-01T00:00:00.000'
> }
> but I expect to get :
> {
> 'ecm__id': '00000000-0000-0000-0000-000000000000',
> 'ecm__minorVersion': 1,
> 'ecm__racl': [ 'Administrator', 'Members' ],
> 'dc__modified': '1970-01-01T00:00:00.000'
> }
>
> How could I patch the document to get the right behaviour ?
>
> I have tried several patch requests, see below a non exhaustive list :
> - put a parent node at root -> same behaviour
> - don't use node('...') in select path -> same behaviour for 1. and error for
> 2. at the first patch
> XDMP-CHILDDUPNAME:
> xdmp:node-insert-after(fn:doc("/00000000-0000-0000-0000-000000000000.json")/text("ecm__id"),
> array-node{text{"Administrator"}, text{"members"}}) -- Object nodes cannot
> have two children with the same name .
> - don't use node('...') in context path -> same behaviour
>
> Thanks
>
> Kevin Leturc Software developer
> Twitter @kevinleturc
> nuxeo.com
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general