Search code examples
marklogicmlcp

Using Transform Module during MLCP Ingestion to MarkLogic


I am trying to implement envelope pattern when i am ingesting documents through MLCP

My transform Module is like this :

function envelope(content, context)
{
  var transformed ={};
  transformed.Metadata = { "Created" : "Time"};
  transformed.Source = content.value;
  content.uri = fn.concat("/transformed/",content.uri);
  content.value = transformed;
};
exports.transform = envelope;

My MLCP Command is like this

    mlcp.bat import -host localhost -port 8000 -username admin -
password admin -mode local -input_file_path D:\Marklogic\abcd.csv -input_file_ty
pe delimited_text -document_type json -transform_module /example/
mlcp-transform.sjs -transform_function transform -output_collections transformed -ge
nerate_uri true

MLCP Error :

    18/01/31 09:00:27 WARN contentpump.TransformWriter: Failed document /D:/Marklogi
c/test.pcr-0-9
18/01/31 09:00:27 WARN contentpump.TransformWriter: TypeError: Cannot read prope
rty 'uri' of undefined
18/01/31 09:00:27 WARN contentpump.TransformWriter: TypeError: Cannot read prope
rty 'uri' of undefined

I don't know why it cant able to read the uri in my transform module. Any help is appreciated

Thanks


Solution

  • MLCP expects the transform function to return an the updated content argument. Try the following:

    function envelope(content, context)
    {
      var transformed ={};
      transformed.Metadata = { "Created" : "Time"};
      transformed.Source = content.value;
      content.uri = fn.concat("/transformed/",content.uri);
      content.value = transformed;
      return content;
    };
    exports.transform = envelope;
    

    Provide target collection names with the -output_collections parameter. You can also prefix uri with /transformed/ using the -output_uri_prefix, or the -output_uri_replace parameter.

    You can find documentation about command-line options here:

    http://docs.marklogic.com/guide/mlcp/import#id_23879

    Documentation about MLCP transforms can be found here:

    http://docs.marklogic.com/guide/mlcp/import#id_82518

    HTH!