本文介绍了在MongoDB中配置GridFS块大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究使用MongoDB来存储电子邮件数据.由于电子邮件的大小可能会变得很大(例如10兆).

I'm currently investigating to use MongoDB for storing E-Mail data. As E-Mails may become rather big in size (say 10 megs).

我相信GridFS将是一个很好的选择.使我感到有些棘手的是,文档对gridFS中的分片大小不是很清楚.据我了解,gridFS中的分片大小不等于正常的分片大小,但默认为256kb.对我来说,这听起来像是在浪费大量空间,因为许多电子邮件的大小不会超过50kb.

I believe that GridFS would be a good fit for this. What scares me a bit tough is, that the docs are not very clear about the shard size within gridFS. From what I understand is, that the shard size in gridFS is not equal to the normal shard size but defaults to 256kb. Which sounds to me like a big waste of space, as many e-mails will not exceed 50kb in size.

是否可以在GridFS中配置文件的分片大小以使其更适合存储邮件?

Is there a way to configure the shard size of files in GridFS to make it more adequate for storing mails?

干杯,马蒂亚斯(Matthias)

Cheers, Matthias

推荐答案

您不必担心大小.即使块大小为256kb,一个50kb的文档(包含您的电子邮件)仍将仅使用50kb(加上较小的开销).

You do not have to worry about size. Even if the chunksize is 256kb, a document (containing your email) of 50kb, will still just use 50kb (+ minor overhead).

chunksize在驱动程序中配置.例如,使用PHP驱动程序,您可以这样做:

The chunksize is configured in the driver. For example with the PHP driver you would do:

$gridFs->storeFile( 'filename.txt', array( 'chunkSize' => 50 * 1024 ) );

在Java驱动程序中,您将调用 setChunkSize GridFSInputFile .

And in the Java driver you'd call setChunkSize on GridFSInputFile.

但是通常,您不必担心chunkSize.

But in general, you shouldn't have to worry about the chunkSize.

这篇关于在MongoDB中配置GridFS块大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 18:47