Hi, Kevin:

The fundamental issue here is that, in the insert case, the goal is to add a 
key but, in the replace case, the goal is to change the value. The two cases 
require different content.

Unfortunately, there's no good solution at present using a patch request.

The easiest alternative is to read the document, modify it on the client, and 
write the document back.

The most efficient alternative to install some server-side JavaScript or XQuery 
that reads and modifies the document using the xdmp.node*() functions and then 
invoke the server-side module.  See:

    http://docs.marklogic.com/guide/rest-dev/extensions#id_59188

Working with your support contact to create a bug would also be appropriate.


Hoping that helps,


Erik Hennum


________________________________
From: [email protected] 
[[email protected]] on behalf of Kevin Leturc 
[[email protected]]
Sent: Wednesday, April 06, 2016 1:14 AM
To: [email protected]
Subject: Re: [MarkLogic Dev General] Need help on document patch operation with 
replace-insert

Hi Geert,

I try to patch document with this java call :

PatchHandle patch = ...
docManager.patch("/00000000-0000-0000-0000-000000000000.json", patch);

The document to update is :
{
    "ecm__id": "00000000-0000-0000-0000-000000000000",
    "ecm__racl": [ "Administrator", "Members" ],
    "dc__modified": "1970-01-01T00:00:00.000"
}

The first time, I want to insert { "ecm__minorVersion": 0 } with this call :
{
"pathlang": "xpath",
"patch": [{
"replace-insert": {
"select": "/node('ecm__minorVersion')",
"context": "/node('ecm__id')",
"position": "after",
"content": {
"ecm__minorVersion": 0
}
}
}]
}

The document is updated to :
{
"ecm__id": "00000000-0000-0000-0000-000000000000",
"ecm__minorVersion": 0,
"ecm__racl": ["Administrator", "Members"],
"dc__modified": "1970-01-01T00:00:00.000"
}

Then I want to update ecm__minorVersion to 1, with this call :
{
"pathlang": "xpath",
"patch": [{
"replace-insert": {
"select": "/node('ecm__minorVersion')",
"context": "/node('ecm__id')",
"position": "after",
"content": {
"ecm__minorVersion": 1
}
}
}]
}

The document is updated to :
{
"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 this :
{
"ecm__id": "00000000-0000-0000-0000-000000000000",
"ecm__minorVersion": 1,
"ecm__racl": ["Administrator", "Members"],
"dc__modified": "1970-01-01T00:00:00.000"
}

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
- don't use node('...') in context path -> same behaviour

Thanks for your help
Regards


Kevin Leturc Software developer
Twitter @kevinleturc
nuxeo.com<https://www.nuxeo.com>

[www.nuxeo.com - Content Management Platform]<http://www.nuxeo.com>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to