-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
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 } }