title: How to perform Update operations in GridFS (using Java)?
body: <p>I am using <code>Mongo-Java-Driver 2.13</code> I stored a PDF file (<em>size 30mb</em>) in <strong>GridFS</strong>. I am able to perform insertion, deletion and find operation easily. </p>
  
  <pre><code>    MongoClient mongo = new MongoClient("localhost", 27017);
      DB db = mongo.getDB("testDB");
      File pdfFile = new File("/home/dev/abc.pdf");
      GridFS gfs = new GridFS(db,"books");     
      GridFSInputFile inputFile = gfs.createFile(pdfFile);
      inputFile.setId("101");
      inputFile.put("title", "abc");
      inputFile.put("author", "xyz");
      inputFile.save();
  </code></pre>
  
  <p>data is persisted in <code>books.files</code> and <code>books.chunks</code> collections. Now I want to <strong>update</strong> :</p>
  
  <ul>
  <li>case 1: pdf file</li>
  <li>case 2: title or author</li>
  </ul>
  
  <blockquote>
    <p>How to perform these Update operations for <strong>Case 1</strong> in GridFS ?</p>
  </blockquote>
  
  <p>I came to know that I need to maintain multiple versions of my files and pick up the right version. Can anybody put some clarity on it?</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>I can update metadata(title, author) easily.</p>
  
  <pre><code>    GridFSDBFile outputFile = gfs.findOne(new BasicDBObject("_id", 101));
      BasicDBObject updatedMetadata = new BasicDBObject();
      updatedMetadata.put("name", "PG");
      updatedMetadata.put("age", 22);
  
      outputFile.setMetaData(newMetadata);       
      outputFile.save();
  </code></pre>