Azure 上的文档数据库使用情况

Document Db Usage on Azure

在我们的项目中,我们尝试在我们的 nosql 数据库中存储大文件,例如图像。在进行一些研究时,我们听说了 Azure Cloud Platform 中的 Document Db nosql 数据库。此外,我们会将数据存储在 Azure 中。

在 Azure 平台中存储大文件的最佳方式是什么?, Document Db 是否足够好? 在 Azure 中使用 MongoDb 合适吗?

虽然 DocumentDB 允许您存储文件(它们作为附件存储),但我不推荐使用它。以下是我的理由:

  • 在当前版本中,附件的最大大小为 2 MB。
  • 您无法真正流式传输附件。您需要先阅读应用程序中的附件内容并从那里进行流式传输。

为了在 Azure 中存储文件,我强烈建议您使用 Blob Storage。它仅用于此目的。您可以在 blob 存储中存储的文件的最大大小为 1 TB(我认为这对您来说已经足够了),每个存储帐户最多可以容纳 500 TB 的数据。此外,您可以直接将文件流式传输给最终用户。

DocumentDB 允许您向文档添加文件,称为 attachments。使用该功能的优点是附件的存储与文档的生命周期相关:如果删除文档,则附件也会被删除。

由于 DocDB 仍处于预览阶段,一旦服务进入全面可用性,您可以预期上述限制会有所不同。

您不必将附件存储在 DocDB 本身中。 DocDB 允许您这样做,或者将对文件的引用简单地存储为附件元数据的一部分。如果您想将文件存储在其他地方,但需要在 DocDB 文档中引用其位置,这很有用。来自 documentation:

DocumentDB allows you to store binary blobs/media either with DocumentDB or to your own remote media store. It also allows you to represent the metadata of a media in terms of a special document called attachment. An attachment in DocumentDB is a special (JSON) document which references the media/blob stored elsewhere. An attachment is simply a special document which captures the metadata (e.g. location, author etc.) of a media stored in a remote media storage.

如果您需要将非常大的文件存储到 Azure(如视频文件或大型工程文件),最好(也是最便宜)的选择可能是将数据存储在 Block Blob 中。然后您可以获取 blob 的 Uri 并将其作为附件元数据存储在您的 docdb 文档中。

存储文件的首选机制是 Blob 存储,因为它很便宜。请记住,文档数据库非常昂贵,因此将文件路径存储在 Blob 存储中时使用 Azure 表。