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

GridFSInputFile.getMetaData() returns wrong value

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5
    • Affects Version/s: 2.4
    • Component/s: None
    • None
    • Minor Change

      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".

            Assignee:
            antoine Antoine Girbal
            Reporter:
            fluffy Ryan Krebs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: