[JAVA-1911] java.lang.IllegalStateException: No GridFS instance defined! Created: 03/Aug/15 Updated: 27/Nov/16 Resolved: 07/Aug/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | GridFS |
| Affects Version/s: | 3.0.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Pavan [X] | Assignee: | Ross Lawley |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 64 bit |
||
| Description |
|
GridFS is failing to write the file. After creating a GridFS class and storing few files to mongodb. I am trying to read it back. DBCursor cursor = fs.getFileList(); GridFSDBFile object = (GridFSDBFile)cursor.next(); catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } count++; |
| Comments |
| Comment by Ross Lawley [ 07/Aug/15 ] | ||||||||
|
Marking as "Won't Fix" as there are no plans to change the existing com.mongodb.gridfs version of GridFS. However, there are improvements are being made to the forthcoming com.mongodb.client.gridfs that will meet the new GridFS specification. | ||||||||
| Comment by Ross Lawley [ 07/Aug/15 ] | ||||||||
|
Hi PavanKua, The reason for the error is due to the casting of a DBObject into a GridFSDBFile, this fails because the DBObject doesn't have access to the GridFS instance. There are two possible approaches: 1. Use fs.find(new DBObject()) to return a List<GridFSDBFile> and then iterate through. eg:
2. Inside the while loop call the gridFS.findOne method for each file eg:
Unfortunately, there are downsides to both, the size in memory for 1. versus the number of queries in 2. Ross |