简体   繁体   English

在MarkLogic中保存带有嵌入式二进制附件列表的JSON文档

[英]Save a JSON document with a list of embedded binary attachments in MarkLogic

Given an entity for example: 以一个实体为例:

public class Page {
   private String description;
   private List<File> attachments; //is it a File or maybe bytes???
}

Is it possible (or even advisable) to save this as a JSON document in MarkLogic with the attachments as embedded documents? 是否可以(甚至建议)将此文件另存为MarkLogic,并将附件另存为嵌入式文档?

If so: 如果是这样的话:

  1. How? 怎么样? Just by using client.newJSONDocumentManager() even if mixed w/ binary data? 即使混合使用二进制数据,也仅通过使用client.newJSONDocumentManager()?
  2. Will the JSON document's attachments field retain the filename for each File? JSON文档的附件字段会保留每个文件的文件名吗?

Else if not, should I save the page as a JSON document and for each attachment, save as a separate binary document in MarkLogic, but how to relate each other (how can I link them with some sort of foreign key)? 否则,我是否应该将页面另存为JSON文档,并将每个附件另存为MarkLogic中的单独的二进制文档,但是如何彼此关联(如何将它们与某种外键链接)?

You can organize your data however you choose. 您可以选择组织数据。 Normally, you would write each binary document/attachment as its own document with its own uri in ML Server. 通常,您将在ML Server中将每个二进制文档/附件作为自己的uri编写为自己的文档。 Generally you would choose the uri for each in your application. 通常,您将在应用程序中为每个用户选择uri。 Therefore you could add that list of uris to the parent document. 因此,您可以将该uris列表添加到父文档中。 Something like the following: 类似于以下内容:

{ description: "some description",
  attachments: [
     "/my/dir/attachments/attachment_1.bin",
     "/my/dir/attachments/attachment_2.bin",
     "/my/dir/attachments/attachment_3.bin"
  ]
}

You can create batches containing both parent documents and binary attachments using DocumentWriteSet. 您可以使用DocumentWriteSet创建包含父文档和二进制附件的批处理。 You could then use JSONDocumentManager.write(documentWriteSet) to send them to the server (see Writing Multiple Documents ). 然后,您可以使用JSONDocumentManager.write(documentWriteSet)将它们发送到服务器(请参阅编写多个文档 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM