[JAVA-764] Facing a 'no more' RuntimeException on DBCursor#next() when DBCursor#count() == 1 Created: 20/Feb/13 Updated: 20/Feb/13 Resolved: 20/Feb/13 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 2.9.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Brice Laurencin | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | cursors, java | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
$ uname -a |
||
| Description |
|
Hello, I am reading data from mongo in Java, with this code:
I somtimes get an Exception on `DBObject lockDBO = lock.next();`: java.lang.RuntimeException: no more How can this be? Thanks for your precious help. |
| Comments |
| Comment by Jeffrey Yemin [ 20/Feb/13 ] |
|
Also, I'm not sure what the intention of this code is, but if you're using a document as a mutex of some sort, you may need to mutate it atomically so that only one client can hold the lock. For that, you can look at http://docs.mongodb.org/manual/reference/command/findAndModify/. |
| Comment by Scott Hernandez (Inactive) [ 20/Feb/13 ] |
|
The find, and count methods are two separate server calls. Instead of using count() == 1 check that lock.hasNext() is true or do a findOne. |