您可以使用
ExportToWriterListener
! ExportToWriterListener导出QueryBatcher检索到的所有内容并写入文件。
DatabaseClient client = DatabaseClientFactory.newClient("localhost", 8012,
new DatabaseClientFactory.DigestAuthContext("admin", "admin"));
DataMovementManager moveMgr = client.newDataMovementManager();
ServerTransform transform = new ServerTransform("transformName");
File outputFile = new File("output.txt"); // pass in your file here
String collection = "customers";
StructuredQueryDefinition query = new StructuredQueryBuilder().collection(collection); // Substitute your query here
try (FileWriter writer = new FileWriter(outputFile)) {
ExportToWriterListener exportListener = new ExportToWriterListener(writer)
.withRecordSuffix("\n")
.withTransform(transform) // pass in your Server Transform here
.onGenerateOutput(
record -> {
String contents = record.getContentAs(String.class);
return contents; // return the content as it is which is the server transformed documents' content
}
);
QueryBatcher queryJob =
moveMgr.newQueryBatcher(query)
.withThreadCount(5)
.withBatchSize(10)
.onUrisReady(exportListener)
.onQueryFailure( throwable -> throwable.printStackTrace() );
moveMgr.startJob( queryJob );
queryJob.awaitCompletion();
moveMgr.stopJob(queryJob);
}
然后您可以创建文件的zip。