Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1013

Saved extra fields for Gridfs does not go in metadata sub-document

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.1.0
    • Affects Version/s: 2.11.1
    • Component/s: GridFS
    • Environment:
      mongodb working at ubuntu 11 x64.
      mongodb-java-driver is running on Win7x64. Using Netbeans, JDK 1.6

      When put some metadata for a file to save with Gridfs, extradata should go into the metadata field (sub document). But it doesn't.

      Following code demonstrates to issue.

      public void SaveMetadata2() throws Exception {
              String ConnectionString = "mongodb://192.168.11.102:37017/filebox.mycoll";        
              MongoClient moClient;
              MongoClientURI moClientURI;        
              moClientURI = new MongoClientURI(ConnectionString);
              moClient = new MongoClient(moClientURI);                       
              DB db = moClient.getDB(moClientURI.getDatabase());                                         
              GridFS gridfs = new GridFS(db, moClientURI.getCollection());                
              db.requestStart();
              db.requestEnsureConnection();        
              File file1 = new File("e:/fbfiles/image_0001.jpg");
              InputStream ins = new FileInputStream(file1);                     
              GridFSInputFile gif = gridfs.createFile(ins, file1.getAbsolutePath(), true);        
              gif.put("XXX", "YYYY");        
              gif.save();        
              db.requestDone();                
              System.out.println("DONE!");
          }
      

      The expected output of db.mycoll.files.find() is this:

      {
      	"_id" : ObjectId("5259df0cee372f2ba1d547e8"),
              "metadata" : {	"XXX" : "YYYY"},
      	"chunkSize" : NumberLong(262144),
      	"length" : NumberLong(13236),
      	"md5" : "71327240323c5176b4c88b7acab9b010",
      	"filename" : "e:\\fbfiles\\image_0001.jpg",
      	"contentType" : null,
      	"uploadDate" : ISODate("2013-10-12T23:45:16.108Z"),
      	"aliases" : null
      }
      

      But it is saved as this:

      {
      	"_id" : ObjectId("5259df0cee372f2ba1d547e8"),
      	"XXX" : "YYYY",
      	"chunkSize" : NumberLong(262144),
      	"length" : NumberLong(13236),
      	"md5" : "71327240323c5176b4c88b7acab9b010",
      	"filename" : "e:\\fbfiles\\image_0001.jpg",
      	"contentType" : null,
      	"uploadDate" : ISODate("2013-10-12T23:45:16.108Z"),
      	"aliases" : null
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            algorian OptimusPrime
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: