我应该使用 GridFS 还是二进制数据来存储和存储数据?从 MongoDB 检索图像?
我想知道哪个更好/更快:
- 拥有一个单独的文档集合,其中仅包含保存为二进制数据的图像,可能还包含一些元数据。
- 或者使用GridFS来存储图像。
I was wondering which is better/faster:
- Having a separate collection of documents that just contain the image saved as binary data, and possibly some metadata.
- Or using GridFS to store the images.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的图像很小,您可以将它们作为二进制数据存储在集合中的文档中。只需考虑一下,每次查询文档时都会检索它们(除非您从查询中排除“图像”字段)。
但是,如果您的图像较大,我会使用 GridFS。 GridFS 具有一些使其非常擅长处理图像的功能,您应该考虑这些功能:
在性能方面,针对常规文档的读/写应该与针对 GridFS 的读/写没有什么不同。我不认为性能是选择任何一个的区别因素。
我个人的建议是使用 GridFS,但您需要针对您的特定用例进行分析。
希望这有帮助。
If your images are small you can store them as binary data in the documents in your collection. Just consider that you will be retrieving them every time you query your document (unless you exclude the 'image' field from your queries).
However, if your images are larger I would use GridFS. GridFS has some features that make it very good at handling images that you should consider:
In terms of performance, reading/writing against a regular document should be no different than doing it against GridFS. I would not consider performance to be a differentiator in choosing either one.
My personal recommendation is to go with GridFS, but you need to analyze for your particular use case.
Hope this helps.
我使用 GridFS 来存储照片和文档。它非常简单,从集合中检索它以在本地显示或保存也很容易。您可以将元数据与二进制数据一起存储在同一集合中。这样您就不需要创建额外的集合来存储它们。
例如,在我的一个项目中,我存储用户个人资料照片以及用户名、文件类型和上传日期。
I use GridFS to store photos and documents. It's so easy and retrieving it from the collection to display or save locally is easy. You can store metadata along w/ the binary data inside the same collection. This way you don't need to create an additional collection to store them.
For example, in one of my project I store user profile photos along with usernames, file type, and date of upload.
GridFS 的开发是为了以有效的方式处理文件。
http://www.mongodb.org/display/DOCS/When+to +use+GridFS
不要忘记您可能需要翻译数据
到一个文件并返回。
但可以肯定的是,请根据您的使用模式进行性能测试。
GridFS is developed to handle Files in an efficient way.
http://www.mongodb.org/display/DOCS/When+to+use+GridFS
Do not forget that you maybe will have to translate the data
to a file and back.
But to be sure, do a performance test that takes account of your usage pattern.