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

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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.0.0
    • Affects Version/s: 3.0.0
    • Component/s: GridFS, Query Operations
    • None
    • Fully Compatible

      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
          }
      }
      

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            FelixM Felix Müller [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: