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]
[[email protected]] 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
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general