GridFS clarification on file id's, revisions and immutability (c# driver)

360 views
Skip to first unread message

gav

unread,
Nov 2, 2012, 12:53:46 AM11/2/12
to mongod...@googlegroups.com
Hi

I am prototyping a file store on top of GridFS to persist a number of media files.

I have some questions regarding the file id's, revision and immutability of files.

Firstly, I was under the impression that a file stored in GridFS was immutable  If you made a change to the content (not the metadata) a new version was created, same file name but a new id and uploadDate.  MongoDB would keep versions of this file, using the uploadDate to index these revisions.

I have done a test with the C# driver, using Upload then OpenWrite but the file id and data seems the same, am I missing something?

The FindOne has an overload which accepts an integer revision number, what does this represent?  How can you correlate a revision with an integer?

Thanks

Robert Stam

unread,
Nov 2, 2012, 8:36:32 AM11/2/12
to mongod...@googlegroups.com
If you use the MongoGridFS Upload method you will get a new version of the file when you upload a file using an existing file name.

If you use OpenWrite with an existing file name you will be updating the file in place. The C# driver is the only driver that allows you to update a GridFS file in place, and there is some controversy as to whether this should be allowed or not. See:


The issue is that while you are in the middle of updating the existing file it is in an inconsistent state (the length and md5 values in the fs.files metadata are not valid until you close the file again, not to mention that the data is changing). This means that other processes could see an intermediate and inconsistent version of the file, and if your update crashes for some reason the GridFS file is permanently damaged. On the other hand, updating an existing file in place can be a huge performance gain when only a few bytes are changing.

There is currently no way to update an existing GridFS file but have the results be placed in a new version of the file. For that you would have to Download the file to the client, make the changes client side, and Upload the new version.

The version numbers are relative. -1 is the current version. -2 is the previous version. -3 is the one before that, etc... and 1 is the oldest version, 2 is the second oldest version, etc... The version number isn't actually stored with the file, but is used to select a version of the file after sorting the multiple copies by uploadDate.


--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Reply all
Reply to author
Forward
0 new messages