Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo: avoid duplicate files in gridfs

There is a way to avoid duplicate files in mongo gridfs? Or I have to do that via application code (I am using pymongo)

like image 710
tapioco123 Avatar asked May 18 '12 07:05

tapioco123


People also ask

How do I stop MongoDB from inserting duplicate records?

To insert records in MongoDB and avoid duplicates, use “unique:true”.

What is FS in GridFS?

GridFS places the collections in a common bucket by prefixing each with the bucket name. By default, GridFS uses two collections with a bucket named fs : fs. files.

What is the use of GridFS in MongoDB?

GridFS is a driver specification for uploading and retrieving files from MongoDB. It is a specification for storing and retrieving files larger than the 16 MB limit of BSON documents.


1 Answers

The MD5 sum is already part of Mongo's gridfs meta-data, so you could simply set a unique index on that column and the server will refuse to store the file. No need to compare on the client side.

like image 142
Derick Avatar answered Oct 16 '22 08:10

Derick