[CDRIVER-708] mongoc_cursor_more doesn't work as expected Created: 17/Jun/15 Updated: 03/May/17 Resolved: 17/Jun/15 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libmongoc |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Marius Soutier | Assignee: | A. Jesse Jiryu Davis |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
mongoc_cursor_more returns true until mongoc_cursor_next already moved to the end of the cursor. So if I have a collection with one document, mongoc_cursor_more will still return true after I have read the document using mongoc_cursor_next. Only after mongoc_cursor_next returns false, so does mongoc_cursor_more. Here is some example code to illustrate the problem: If I have to query mongoc_cursor_next anyway I'm not sure how mongoc_cursor_more might be useful. |
| Comments |
| Comment by A. Jesse Jiryu Davis [ 17/Jun/15 ] |
|
I'm going to consider this a duplicate of Short story: just use the return value of mongoc_cursor_next. Mid-length story: mongoc_cursor_more is unreliable because it doesn't contact the server to see if there are actually more documents in the result set. It just returns true if the cursor has not begun, or if it has begun and there are buffered documents in the client-side cursor, or if it has begun and the server hasn't yet told the cursor it's completely iterated. This is unreliable with regular queries because it's true of a new cursor before iteration, even if the cursor will match no documents. It's also true if the cursor thinks it can fetch more documents but the collection has been dropped server-side, or if the cursor has finished its final batch and the next batch will be empty. mongoc_cursor_more is somewhat useful with exhaust cursors and tailable cursors, but not at all for regular cursors. Just use mongoc_cursor_next. |