Hi, Desmond:

Thanks for the correction.

The actual limitation is that a PATCH context or select path can't
match an unnamed node (basically, an object or array within an
array).

Apologies for the misinformation, glad you had success.


Erik Hennum


________________________________
From: [email protected] 
[[email protected]] on behalf of Desmond Lim 
[[email protected]]
Sent: Wednesday, January 25, 2017 5:38 PM
To: [email protected]
Subject: Re: [MarkLogic Dev General] Question about patching a JSON document

​Hi Erik,

Thanks for the advice.

I've used the "array-node('tags')" and it works with insert.

As for the other things, we might need to rethink our strategy.​

Thanks.

​Desmond​


​


Date: Wed, 25 Jan 2017 17:51:29 +0000
From: Erik Hennum <[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Question about patching a JSON
        document
To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Message-ID:
        
<dfdf2fd50bf5aa42adaf93ff2e3ca1850bd7c...@exchg10-be01.marklogic.com<mailto:dfdf2fd50bf5aa42adaf93ff2e3ca1850bd7c...@exchg10-be01.marklogic.com>>
Content-Type: text/plain; charset="iso-8859-1"

Hi, Desmond:

The PATCH REST API request has an unfortunate limitation that prevents
clients from specifying an array as the context for a request.

The appropriate XPath expression would be:

    /resource/array-node('tags')

The REST API uses cts.validIndexPath() to sanitize XPaths, which ensures
security without sacrificing performance but prohibits some useful paths
including the one above.

There is an RFE to address the issue, but it is unlikely to be implemented
in ML9.

In the meantime, the alternatives are either to read the document and modify
it on the client or to install server-side code to implement the change.


Erik Hennum


________________________________
From: 
[email protected]<mailto:[email protected]>
 
[[email protected]<mailto:[email protected]>]
 on behalf of Desmond Lim 
[[email protected]<mailto:[email protected]>]
Sent: Wednesday, January 25, 2017 12:11 AM
To: [email protected]<mailto:[email protected]>
Subject: [MarkLogic Dev General] Question about patching a JSON document

Hi there,

I have this document in Marklogic:

{
"resource":
{
"name": "hrRFIrq2JzpiXmc",
"url": "k4llhWiubj2SHtl",
"importer": "UXwZbxVCOfNFeST",
"text_context": "qerXqhThyAtdQkNhXZ2FMZwY5JIX4quQTwQwHflsw3hl2RZNYu",
"title": "QBV877tmh5Y18Z2",
"subject": "8NPCWTGUF5k5iYB",
"author": "xnONnboaNlaL7q5",
"author_role": "tu8kTbQn0yWNMX1",
"author_organisation": "x36qaVbgIXuHgCw",
"tags":
[
{
"tag": "AoFCPDLY33A4fww",
"class": "L52uePB2HcklJu2"
}
,
{
"tag": "7ByYULGv36DhTSa",
"class": "NUjndXpM2y8wQ2g"
}
,
{
"tag": "4MRydSIXDBHcqaE",
"class": "v17DV2Xgkjh6AZq"
}
,
{
"tag": "2nFrUOh0lKGwVUJ",
"class": "NmSIjx2nqd7SIp4"
}
],
"comments": "GtdMrgackvjcP2s",
"date_created": 808426552630988,
"date_modified": 44633806482503
}
}

And I'm trying to add more objects to the Tags Array.

I've tried this:

ObjectNode fragmentNode = mapper.createObjectNode();
fragmentNode.put("tag", "blahblah");
fragmentNode.put("class", "the class");
String fragment = mapper.writeValueAsString(fragmentNode);
documentPatchBuilder.insertFragment("/resource/tags", 
DocumentPatchBuilder.Position.LAST_CHILD, fragment);

And also this:

ObjectNode fragmentNode = mapper.createObjectNode();
fragmentNode.put("tag", "blahblah");
fragmentNode.put("class", "the class");
String fragment = mapper.writeValueAsString(fragmentNode);

documentPatchBuilder.replaceInsertFragment("/documents/thefile.json", 
"/resource/tags", DocumentPatchBuilder.Position.LAST_CHILD, fragment);

But I keep getting this error message : Object nodes cannot have two children 
with the same name.

Now nodes that I'm inserting (insertFragment) works, only this "adding to 
existing" doesn't.

Anyone can point me in the right direction?

Thanks.

Desmond

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://developer.marklogic.com/pipermail/general/attachments/20170125/f07a50f7/attachment-0001.html

------------------------------

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general


End of General Digest, Vol 151, Issue 39
****************************************

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to