Neo
Neo

Reputation: 5228

Understanding mongodb md5 key in GridFS files collection

Please explain the usage of md5 key in GridFS files collection.

In mongodb GridFS reference it says: "An MD5 hash returned from the filemd5 API. This value has the String type.", What is need for this hash ?

Upvotes: 2

Views: 3624

Answers (2)

Almog Cohen
Almog Cohen

Reputation: 1313

I use the md5 field to make sure I update the file only if it was changed without having to fetch the whole file from the DB and compare it.

I do db.col_name.find({id: myid}, {md5: 1}) so I fetch only the md5 field, I calculate the md5 of the new file, and update only if needed.

Fetching the whole file and making full data comparison could be very slow and traffic expensive.

Upvotes: 0

lese
lese

Reputation: 549

I tryied to understand that too some weeks ago, and i still have some doubt, but i report to you what i had read here

A kind of safe mode is built into the GridFS specification. When you save a file, and MD5 hash is created on the server. If you save the file in safe mode, an MD5 will be created on the client for comparison with the server version. If the two hashes don't match, an exception will be raised.

I guess it's a kind of check to see if the file is being update correctly[?]

edit: found that short sentence too, in official mongodb site, give a look http://docs.mongodb.org/manual/reference/command/filemd5/

Upvotes: 3

Related Questions