简体   繁体   English

如何通过SimpleSchema将图像插入到mongodb

[英]How to insert image to mongodb via SimpleSchema

How can I define a SimpleSchema template to store image data/binary data inside a mongodb storage. 如何定义SimpleSchema模板以在mongodb存储中存储图像数据/二进制数据。

What is the type I should use? 我应该使用哪种类型? Should I use Object type? 我应该使用对象类型吗?

You can use Buffer type to store image. 您可以使用缓冲区类型来存储图像。

But there is size limit of 16 MB for BSON-document so GridFS may help you to store files larger than 16 MB. 但是BSON文档的大小限制为16 MB,因此GridFS可以帮助您存储大于16 MB的文件。

It's not always a good idea to store images or other files in MongoDB database(or any other database). MongoDB数据库(或任何其他数据库)中存储图像或其他文件并不总是一个好主意。 Rather store them in a separate Storage server like AWS S3 or Azure blob storage or whatever storage server and keep the link to the file in your MongoDB database. 而是将它们存储在单独的存储服务器(例如AWS S3Azure blob storage或任何存储服务器中,并将指向文件的链接保留在MongoDB数据库中。 It will help you keep the DB server lean. 这将帮助您保持数据库服务器的精益。

For more details study on multi-tier application architecture . 有关更多详细信息,请研究multi-tier application architecture

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

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