marklogic mlcp custom transform split aggregate document to multiple files

拥有回忆 提交于 2019-12-12 11:07:50

问题


I have a JSON "aggregate" file that I want to split up and ingest as multiple documents into MarkLogic using mlcp.

I want to transform the content during ingestion using javascript.

My JSON file looks something like this:

{
  "type": "FeatureCollection",
  "features": [
    {blobA}, {blobB}, {blobC} ......
    ]
 }

...and I want to run this file through MLCP so that each document contains an item in the array.

i.e. One document will contain {blobA}, another will contain {blobB}, and another will contain {blobC}....and so forth.

How do I write my custom .sjs transform module?


回答1:


Check out the example here: 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
}

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.

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;

As an aside, this is a useful resource when working with JSON in MarkLogic.



来源:https://stackoverflow.com/questions/36506412/marklogic-mlcp-custom-transform-split-aggregate-document-to-multiple-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!