问题描述
一段时间以来,我一直在尝试阅读GridFS和MongoDB的文档.他们只是不断重复同样的事情,而我对此一无所知.
I have been trying to read the documentation for GridFS and MongoDB for awhile. They just keep repeating the same thing and I can't make sense of it.
所需的输出:用户提交的表单包含许多字段,但其中一个是图像.该请求需要将数据存储在集合中并创建一个新文档,以便以后检索.我的主要问题是在这种情况下如何使用GridFS将图像存储在该文档中.
Desired Output: The user submits a form that form contains many fields, but one is an image. The request needs to store the data in a collection and make a new document, which can be retrieved later. My main question is how do I use GridFS in this situation to store an image in that document.
它说GridFS在我的数据库文件和块中创建了两个集合.那么这些集合与我的另一个具有其他表单数据的集合有什么关系?
It says GridFS makes two collections in my database files and chunks. So how do those collections relate to my other collection which has the other form data?
我假定对这些文件和chuck集合的引用,但是,我对此毫无意义.已经过了几天,我觉得是时候联系我的StackOverflow社区了.
I assume a reference to these files and chucks collection, however, I can't make any sense of this. It's been a few days and I feel like it's time to reach out to my StackOverflow community.
有人可以向我说明程序流程和关键点,以说明我如何实现使用gridfs将图像存储在文档中的目标吗?
GridFS到处都有提及,并且似乎很流行,但我无法理解.这些完全混乱的时刻通常会带来突破,所以我渴望向退伍军人和专家学习.
GridFS is mentioned everywhere and seems to be popular but I can't make sense of it. These moments of utter confusion usually result in a breakthrough, so I'm eager to learn from veterans and experts.
推荐答案
GridFS集合是GridFS的内部实现细节.它们与您的其他数据之间没有链接.
GridFS collections are internal implementation detail of GridFS. There is no linking between them and your other data.
要写入GridFS和从中读取数据,您将使用驱动程序提供的GridFS API.通常,这意味着,例如,如果要保存某些字段和类似于图像的二进制Blob,则将分两步执行保存(对字段执行一次插入/更新操作,对二进制Blob执行单独的GridFS操作)./p>
To write to and read from GridFS, you would use GridFS APIs provided by your driver. Generally this means that, if you are saving for example some fields and a binary blob like an image, you would perform the save in two steps (one insert/update operation for the fields and a separate GridFS operation for the binary blob).
您不会将图像存储在文档中.您将图像存储在GridFS 中,并且在您的文档中可以包含对GridFS文件的引用(它们具有自己的ID).
You wouldn't store the image in your document. You would store the image in GridFS, and in your document you could include a reference to the GridFS file (those have their own ids).
这篇关于像我五岁一样解释:带文字和图像字段的表格>路线>控制器>写入MongoDB文档-GridFS去哪里了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!