MarkLogic - mlcp export to a single output file

2019-08-15 18:09发布

MarkLogic version 9.0-6.2

mlcp version 9.0.6

I have a customer collection with each document having a customer root node, as below.

<customer>
  <customerId>123</customerId>
  ....
</customer>

My need is to export all documents in the collection into one single output file under a new root called customerinfo

<customerInfo>
    <customer>
      <customerId>123</customerId>
      ....
    </customer>
    <customer>
      <customerId>456</customerId>
      ....
    </customer>
</customerInfo>

Using below code, I am able to export the collection as individual documents under a directory.

mlcp.sh export -ssl \
-host localhost \
-port 8010 \
-username uname \
-password pword \
-mode local \
-output_file_path /test/TestFiles/customer \
-collection_filter customer \
-output_type document

Is it possible to aggregate output into one single document, under a new root node?

2条回答
Summer. ? 凉城
2楼-- · 2019-08-15 18:25

No. mlcp can transform documents during import, but not during export. Merging query results into a single document is fairly simple to do in XQuery, though:

xdmp:save('/test/TestFiles/customer/merged.xml',
  <root>{ collection('customer') }</root>
)

You could also look into other MarkLogic tools like corb or the Data Movement SDK.

查看更多
走好不送
3楼-- · 2019-08-15 18:36

ml-gradle has some tasks that use MarkLogic's Data Movement SDK so that you ideally don't need to write any code to do this - https://github.com/marklogic-community/ml-gradle/wiki/Exporting-data

查看更多
登录 后发表回答