[JAVA-1180] Inconsistent behaviour when querying GridFS collection Created: 25/Apr/14 Updated: 16/Nov/21 Resolved: 28/Apr/14 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | GridFS |
| Affects Version/s: | 2.12.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Torsten Spindler | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Mac OS X |
||
| Attachments: |
|
| Description |
|
When querying a GridFS collection on specific fields, it works when no GridFS file was ever stored on that collection. Once a file was saved to the collection, the query on specific fields fails with "can't load partial GridFSFile file". Probably the driver uses 'BasicDBObject' for the query until it associates GridFS with the collection? |
| Comments |
| Comment by Ross Lawley [ 28/Apr/14 ] |
|
Hi, A collection can have an associated ObjectClass and this information is cached, allowing it to be set once and then reused elsewhere in your code. Once it is set you have to explicitly unset it. GridFS is a specification for storing and retrieving files that is built upon the driver. GridFS is opinionated about how it is to be used, as such it sets the ObjectClass for the files collection when you create a GridFS instance. The reason it throws an error is the GridFSFile is not expected to be used in the way you've show as it could represent a partial part of a file and which is why it throws the "can't load partial GridFSFile file" runtime error. As you've found out the associated ObjectClass can only unset by resetting the ObjectClass back to null. Ross |
| Comment by Torsten Spindler [ 25/Apr/14 ] |
|
For now I'll reset the object associated with the collection, quite a hack though: if (Objects.equal(GridFSDBFile.class, coll.getObjectClass())) { coll.setObjectClass(null); } |