[JAVA-1013] Saved extra fields for Gridfs does not go in metadata sub-document Created: 13/Oct/13  Updated: 07/Apr/23  Resolved: 02/Sep/15

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 2.11.1
Fix Version/s: 3.1.0

Type: Bug Priority: Minor - P4
Reporter: OptimusPrime Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongodb working at ubuntu 11 x64.
mongodb-java-driver is running on Win7x64. Using Netbeans, JDK 1.6



 Description   

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
}



 Comments   
Comment by Ross Lawley [ 02/Sep/15 ]

Fixed in the new GridFS implementation JAVA-1713

Reading legacy metadata stored outside the metadata document is supported.

Comment by Jeffrey Yemin [ 14/Oct/13 ]

I tried this with the 2.9.3 driver and got the exact same results as you did with 2.11.3. Are you seeing something different?

Comment by OptimusPrime [ 13/Oct/13 ]

I am perfectly sure about that it is working in mongodb 2.2.1 with java-driver 2.9.3..
This is a fundamental breakdown in application.

Comment by Jeffrey Yemin [ 13/Oct/13 ]

See http://docs.mongodb.org/manual/reference/gridfs/#files.metadata.

Have to think about this one a bit. While doing this would be to spec, it would be a breaking change for applications relying on the current behavior.

One option would be to write to both locations during a transition period.

Generated at Thu Feb 08 08:53:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.