MarkLogic版本9.0-6.2
mlcp版本9.0.6
我有一个客户集合,每个文档都有一个客户根节点,如下所示。
<customer>
<customerId>123</customerId>
....
</customer>
我需要将集合中的所有文档导出到一个名为customerinfo的新根目录下的单个输出文件中
<customerInfo>
<customer>
<customerId>123</customerId>
....
</customer>
<customer>
<customerId>456</customerId>
....
</customer>
</customerInfo>
使用下面的代码,我可以将集合导出为目录下的单个文档。
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
是否可以在新的根节点下将输出聚合到一个文档中?
不.mlcp可以在导入期间转换文档,但不能在导出期间转换文档。但是,在XQuery中将查询结果合并到单个文档中相当简单:
xdmp:save('/test/TestFiles/customer/merged.xml',
<root>{ collection('customer') }</root>
)
您还可以查看其他MarkLogic工具,如corb或Data Movement SDK。
ml-gradle有一些使用MarkLogic的Data Movement SDK的任务,因此理想情况下你不需要编写任何代码来执行此操作 - https://github.com/marklogic-community/ml-gradle/wiki/Exporting-data