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
}