GridFS 和原子更新
GridFS and atomic updates
我正在考虑使用 MongoDB GridFS 来存储和检索图像,但阅读官方文档 (https://docs.mongodb.com/manual/core/gridfs/) 我无法理解以下部分:
Do not use GridFS if you need to update the content of the entire file atomically. As an alternative you can store multiple versions of each file and specify the current version of the file in the metadata. You can update the metadata field that indicates “latest” status in an atomic update after uploading the new version of the file, and later remove previous versions if needed.
他们说:"update the content of the entire file atomically" 是什么意思?如果我需要更新存储的图像怎么办?存储的文件会怎样?
GridFS 将文件的内容分成块(这样每个块就不会超过 16 MB 的文档大小限制)。
如链接文档所述,GridFS 不支持事务。没有事务,只有对一个文档的单个操作是原子的,但是 GridFS 可以对多个文档执行操作,这不是原子的。
此外,文件元数据和文件内容是分开存储的,同样不会自动写入。
What if I need to update a stored image?
您可以插入新图像,然后(自动)更新其他文档以引用新上传的图像。
我正在考虑使用 MongoDB GridFS 来存储和检索图像,但阅读官方文档 (https://docs.mongodb.com/manual/core/gridfs/) 我无法理解以下部分:
Do not use GridFS if you need to update the content of the entire file atomically. As an alternative you can store multiple versions of each file and specify the current version of the file in the metadata. You can update the metadata field that indicates “latest” status in an atomic update after uploading the new version of the file, and later remove previous versions if needed.
他们说:"update the content of the entire file atomically" 是什么意思?如果我需要更新存储的图像怎么办?存储的文件会怎样?
GridFS 将文件的内容分成块(这样每个块就不会超过 16 MB 的文档大小限制)。
如链接文档所述,GridFS 不支持事务。没有事务,只有对一个文档的单个操作是原子的,但是 GridFS 可以对多个文档执行操作,这不是原子的。
此外,文件元数据和文件内容是分开存储的,同样不会自动写入。
What if I need to update a stored image?
您可以插入新图像,然后(自动)更新其他文档以引用新上传的图像。