Mongo: avoid duplicate files in gridfs

Is there a way to avoid duplicate files in mongo gridfs? Or should I do this using application code (I use pymongo)

+4
source share
2 answers

The MD5 sum is already part of the Mongo gridfs metadata, so you can simply set a unique index on this column and the server will refuse to store the file. No need to compare on the client side.

+4
source

You can use the md5 hash and compare the new hash with the existing one before saving the file.

+1
source

Source: https://habr.com/ru/post/1413123/


All Articles