marklogic mlcp 自定義轉換將聚合文檔拆分為多個文件 (marklogic mlcp custom transform split aggregate document to multiple files)


問題描述

marklogic mlcp 自定義轉換將聚合文檔拆分為多個文件 (marklogic mlcp custom transform split aggregate document to multiple files)

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.

(by jenniferjennifer)

參考文件

  1. marklogic mlcp custom transform split aggregate document to multiple files (CC BY‑SA 2.5/3.0/4.0)

#javascript #mlcp #marklogic #JSON






相關問題

為什麼我不能在 IE8 (javascript) 上擴展 localStorage? (Why can't I extend localStorage on IE8 (javascript)?)

在 Javascript 中打開外部 sqlite3 數據庫 (Open external sqlite3 database in Javascript)

Javascript:數組中的所有對像都具有相同的屬性 (Javascript: All Objects in Array Have Same Properties)

為什麼我們要在 javascripts 原型中添加函數? (Why do we add functions to javascripts prototype?)

顯示 URL javascript 的最後一部分? (Display the last part of URL javascript?)

Javascript XMLHttpRequest:忽略無效的 SSL 證書 (Javascript XMLHttpRequest: Ignore invalid SSL Certificate)

有沒有辦法測試 console.log 整體 (Is there a way to test for console.log entires)

如何從 javascript 對像中獲取名稱和值到新列表中? (How to get name and values from a javascript object into a new list?)

數據未發布..幫助!html,js,firebase (Data not posting.. Help! html,js,firebase)

使用 Node.js 腳本查看表單數據 (Seeing form data with Node.js script)

使用百分比查找範圍內的值 (find the value within a range using percent)

如何通過 react.js 中的組件傳遞變量或數據? (How to pass varible or data through components in react.js?)







留言討論