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]>
> Subject: Re: [MarkLogic Dev General] Question about patching a JSON
> document
> To: MarkLogic Developer Discussion <[email protected]>
> Message-ID:
> <DFDF2FD50BF5AA42ADAF93FF2E3CA1850BD7C156@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] [general-bounces@developer.
> marklogic.com] on behalf of Desmond Lim [[email protected]]
> Sent: Wednesday, January 25, 2017 12:11 AM
> To: [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]
> 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