[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:
Duplicate
duplicates CDRIVER-516 Clear instructions for mongoc_cursor_... Closed

 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:
http://pastebin.com/fQwX6riE

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 CDRIVER-516. I agree with you that mongoc_cursor_more isn't typically useful, and the C driver's documentation on the function is poor. (Other MongoDB drivers tend to have a similar cursor API, with similarly bad documentation. See PYTHON-660 for the exact same problem with PyMongo.)

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.

Generated at Wed Feb 07 21:10:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.