MongoDB GridFS 是否为 CRUD 操作维护了原子性?
Is atomicity maintained in MongoDB GridFS for CRUD operations?
因为 GridFS 在 fs.chunks
中存储数据块,在 fs.files
中存储元数据。因此,在单个事务中它管理两个集合。是否保证所有 CRUD 操作的原子性?
MongoDB FAQ 是这么说的:
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.
因为 GridFS 在 fs.chunks
中存储数据块,在 fs.files
中存储元数据。因此,在单个事务中它管理两个集合。是否保证所有 CRUD 操作的原子性?
MongoDB FAQ 是这么说的:
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.