如何在mongoDB中添加图像? [英] How can I add images in mongoDB?

查看:80
本文介绍了如何在mongoDB中添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Node和Express将图像添加到我的mongoDB中. 我可以通过运行mongo shell来正常处理数据.但是我找不到任何向其添加图像的方法. 有人可以帮忙吗?

I need to add images to my mongoDB using Node and Express. I am able to normal data in it by running the mongo shell. But I cannot find any method to add images to it. Can anybody help?

推荐答案

请不要这样做.数据库不是特别适合存储大量数据,例如图像,文件等.

Please don't do this. Databases are not particularly well suited to storing large bits of data like images, files, etc.

相反:您应该将图像存储在专用的静态文件存储中,例如 Amazon S3 ,然后存储链接到您的MongoDB记录中的图像.

Instead: you should store your images in a dedicated static file store like Amazon S3, then store a LINK to that image in your MongoDB record.

这在总体性能和功能方面要好得多,因为:

This is a lot better in terms of general performance and function because:

  • 这将减少数据库托管成本(在S3或其他文件服务中存储大文件比在数据库中存储便宜).
  • 这将提高数据库查询性能:DB可以快速查询少量数据,但不能返回大量数据(例如文件).
  • 这将使您的站点或应用程序更快:无需在需要时查询数据库的图像,只需输出图像链接即可立即将其呈现.

总体:这是一种更好/更安全/更快的策略.

Overall: it is a much better / safer / faster strategy.

这篇关于如何在mongoDB中添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆