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

GridFS#findOne(ObjectId) finds by "objectId" instead of "_id"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 3.0.0
    • Component/s: GridFS, Query Operations
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible

      Description

      GridFs#findOne(ObjectId) uses findOne(new BasicDBObject("objectId", objectId)), which does not find anything.
      It should use findOne( new BasicDBObject( "_id" , objectId ) ).

      That is probably just a typo.

      Demo that works with 2.13.0 but not with 3.0.0-beta2:

      Demo.java

      public class Demo {
       
          public static void main(String[] args) throws UnknownHostException {
              MongoClient mongo = new MongoClient("localhost");
              DB db = mongo.getDB("gridDB");
              GridFS gridfs = new GridFS(db);
       
              GridFSInputFile input = gridfs.createFile(new byte[42]);
              input.setContentType("griffins");
              input.save();
       
              String id = input.getId().toString();
       
              GridFSDBFile saved = gridfs.findOne(new ObjectId(id));
              System.out.println("saved: " + saved); // should not be null
          }
      }

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: