问题
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?
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/54621264/marklogic-mlcp-export-to-a-single-output-file