title: How to use MongoDB or other document database to keep video files, with options of adding to existing binary files and parallel read/write
body: <p>I'm working on a video server, and I want to use a database to keep video files. 
  Since I only need to store simple video files with metadata I tried to use MongoDB in Java, via its <a href="http://www.mongodb.org/display/DOCS/GridFS" rel="nofollow">GridFS</a> mechanism to store the video files and their metadata.</p>
  
  <p>However, there are two major features I need, and that I couldn't manage using MongoDB:</p>
  
  <ol>
  <li>I want to be able to add to a previously saved video, since saving a video might be performed in chunks. I don't want to delete the binary I have so far, just append bytes at the end of an item.</li>
  <li>I want to be able to read from a video item while it is being written. "Thread A" will update the video item, adding more and more bytes, while "Thread B" will read from the item, receiving all the bytes written by "Thread A" as soon as they are written/flushed.</li>
  </ol>
  
  <p>I tried writing the straightforward code to do that, but it failed. It seems MongoDB doesn't allow multi-threaded access to the binary (even if one thread is doing all the writing), nor could I find a way to add to a binary file - the Java GridFS API only gives an InputStream from an already existing GridFSDBFile, I cannot get an OutputStream to write to it.</p>
  
  <ul>
  <li>Is this possible via MongoDB, and if so how? </li>
  <li>If not, do you know of any other DB that might allow this (preferably nothing too complex such as a full relational DB)? </li>
  <li>Would I be better off using MongoDB to keep only the metadata of the video files, and manually handle reading and writing the binary data from the filesystem, so I can implement the above requirements on my own?</li>
  </ul>
  
  <p>Thanks,</p>
  
  <p>Al</p>