In docs https://docs.mongodb.com/manual/core/gridfs/ I found this statement:
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.
So I understand that I have to set the new file to latest after uploading it and next remove previous version that had also version latest.
Here I have concern that in such scenario there will be short period of time where I will have 2 latest versions:
- Set the uploaded file to latest version.
- Previously uploaded file has still latest version.
- Delete previous version file.
So in step 2 there are 2 latest versions.
Or you mean that in one atomic transaction I have to update uploaded file version and delete previous file?
I understood the in mongo atomicity is only on single document level always.