[JAVA-261] GridFSInputFile.getMetaData() returns wrong value Created: 25/Jan/11 Updated: 14/May/14 Resolved: 10/Feb/11 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.4 |
| Fix Version/s: | 2.5 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Ryan Krebs | Assignee: | Antoine Girbal |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Backwards Compatibility: | Minor Change | ||||
| Description |
|
When saving a new file, GridFSInputFile overrides getMetadata() to return _metadata instead of _metadata.get("metadata"). As a result, metadata values are saved directly in the files object, not in a field named "metadata" as indicated in the spec. For example, we end up with: { "_id" : ObjectId(...), "chunkSize" : ..., "length" : ..., "myMetadataField" : "myValue" }instead of: { "_id" : ObjectId(...), "chunkSize" : ..., "length" : ..., metadata : { "myMetadataField" : "myValue" }} I would think GridFSInputFile should not override getMetadata() at all, but instead GridFSFile should either provide a setMetadata(DBObject) method or getMetadata() should create an object to return and simply not save it to the database if it's empty. I can currently work around this bug by creating a new BasicDBObject and calling myGridFSInputFile.put("metadata", myBasicDBObject), but in my opinion I shouldn't need to know about the specific implementation of DBObject in use, or the fact that metadata is stored as a field named "metadata". |
| Comments |
| Comment by Brendan W. McAdams [ 25/Feb/11 ] |
|
If you were using metadata previously in GridFS with previous versions (<= 2.4) then you will have breakage of your files... MetaData will be nested in a metadata key on the object. |
| Comment by auto [ 10/Feb/11 ] |
|
Author: {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}Message: |
| Comment by Antoine Girbal [ 10/Feb/11 ] |
|
this is resolved:
Uploaded file now looks like: , "chunkSize" : 262144 , "length" : 1945007 , "md5" : "eeca506d5a94370adc991d717992ecc5" , "filename" : "myimg" , "contentType" : "jpeg" , "uploadDate" : { "$date" : "2011-02-10T18:14:00Z"}, "aliases" : null , "metadata" : { "a" : 1}} Note metadata must be passes as a dbobject, cannot be a string. |