GridFSInputFile.getMetaData() returns wrong value

XMLWordPrintableJSON

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

      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 Girbal (Inactive)
            Reporter:
            Ryan Krebs
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: