Append data to existing gridfs file

邮差的信 提交于 2019-11-29 11:37:37
pingw33n

GridFS is not a core feature of MongoDB but a convention of storing binary data with accompanying metadata. You should be able to modify any document in fs.chunks collection in a usual manner while keeping corresponding document in fs.files intact. The main problem will be recalculating MD5 checksum, but AFAIK it isn't used anywhere and is just a "free" bonus. Anyway it's still possible for appending-only modification (see MD5 digest of a resumed download).

So to append to an existing GridFS file you need to locate corresponding document in fs.files. Then depending on last chunk filling ratio (length % chunkSize == 0) you either rewrite the last chunk document in fs.chunks respecting the chunkSize, and/or simply add new chunk(s) with incrementing n field. Next update length in fs.files and possibly other metadata.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!