0

In mongodb GridFS when you insert a file with the same name as an already existing file the old file becomes a previous version of the new file.

I'm wondering can I do this multiple times and is there a limit?

For example, I have a file file.txt, then I insert another file.txt, now I have two versions of file.txt. I now insert a third file.txt. Do I now have three versions of the file? Or just two? How many more times can I insert file.txt and keep all the previous versions?

Finally, how do I access these previous versions or overwrite them?

toofarsideways
  • 3,956
  • 2
  • 31
  • 51
  • gridfs by default behaviour, unless you have a specific driver that does just that, does not version but instead overwrites. – Sammaye Sep 28 '12 at 16:56

1 Answers1

2

There is no built-in limit on the number of versions, but it may be that a particular driver may set some limit.

As for getting a specific version, are you by any chance using a specific driver? For instance, I believe pyMongo has a get_version() api which allows you to specify a particular version of the file.

As for replacing files, if you're running mongofiles utility in the shell, you can specify -r to replace a document -- such as mongofiles -r put file.txt -- which would leave you with just this version of file.txt. There may be different implementation with specific drivers.

Regards,

Kay

Kay
  • 2,942
  • 18
  • 13
  • Hi @Kay, sorry I didn't make that clear, yes, I will be using `pymongo` and with regards to replacing a document, what I meant was replacing a particular version of that document, so for example the only replacing the second `file.txt`. – toofarsideways Sep 29 '12 at 16:58
  • Hi @toofarsideways -- unfortunately, I don't believe you can swap out earlier versions. – Kay Oct 26 '12 at 21:29