marklogic mlcp定制将拆分的聚合文档转换为多个文件 [英] marklogic mlcp custom transform split aggregate document to multiple files
问题描述
我有一个JSON聚合"文件,我想使用mlcp将其拆分并作为多个文档提取到MarkLogic中.
I have a JSON "aggregate" file that I want to split up and ingest as multiple documents into MarkLogic using mlcp.
我的JSON文件如下所示:
My JSON file looks something like this:
{
"type": "FeatureCollection",
"features": [
{blobA}, {blobB}, {blobC} ......
]
}
...并且我想通过MLCP运行此文件,以便每个文档在数组中都包含一个项目.
...and I want to run this file through MLCP so that each document contains an item in the array.
即一个文档将包含{blobA},另一个文档将包含{blobB},另一个文档将包含{blobC}....依此类推.
i.e. One document will contain {blobA}, another will contain {blobB}, and another will contain {blobC}....and so forth.
如何编写自定义.sjs转换模块?
How do I write my custom .sjs transform module?
推荐答案
在此处查看示例: http://docs.marklogic.com/guide/mlcp/import#id_26044
原始输入文档应采用以下格式:
The original input document is expected to be of the following form:
{ uri: string,
value: node
}
这也是每个文档的预期输出形式.您还希望返回的文档类型为document-node,因为您希望mlcp对其进行拆分并将其作为JSON文档提取.
That is also the expected output form for each document. You'll also want your return to be of type document-node, since you want mlcp to split it up and ingest it as JSON documents.
因此,您的.sjs自定义转换模块将如下所示....
So, your .sjs custom transform module will look something like this....
function splitFeatures(doc) {
const features = doc.value.toObject().features;
return xdmp.arrayValues(
features.map(function(feature) {
return {
uri: '/path/itemhere-' + xdmp.random() + '.json',
value: xdmp.toJSON(feature)
}
})
);
}
exports.transform = splitFeatures;
顺便说一句,这是在MarkLogic中使用JSON时有用的资源.
As an aside, this is a useful resource when working with JSON in MarkLogic.
这篇关于marklogic mlcp定制将拆分的聚合文档转换为多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!