[CXX-866] It will raise runtime error at finish of program when using mongocxx::options::find.limit() Created: 15/Mar/16  Updated: 11/Sep/19  Resolved: 23/Mar/16

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: 3.0.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: zy1989 [X] Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu15.4 Clang3.6.0



 Description   

mongocxx::collection collection = conn["wechat"]["article"];
bsoncxx::builder::stream::document condition, options;
mongocxx::options::find opts;

condition << "subscribeRobot" << open_document << "$exists" << 1 << close_document;
options << "subscribeRobot" << 1;
opts.projection(options.view());
opts.limit(100);

mongocxx::cursor cur = collection.find(condition.view(), opts);
for(auto && doc:cur)

{ cout << bsoncxx::to_json(doc) << endl;}

 Comments   
Comment by zy1989 [X] [ 23/Mar/16 ]

Sorry for relying late, Matt. This error doesn't cause by code pasted here.
It happens when I try to use
int n = 10; // this is in range.
*next(cur.begin(), n)
I have avoid this usage and the error never happen again.
Thanks for all your help.

Comment by Matt Cotter [ 23/Mar/16 ]

Hello!

It's been a while with no news; I'm closing this for now.
Please reopen is you still need assistance with this.

Thanks!
-Matt

Comment by Matt Cotter [ 16/Mar/16 ]

New update! The official word is that

{mongoc_cursor_next}

is supposed to work as we expect.

LeoZhao - can you consistently reproduce this? If so, would you mind posting a dump of the data that you use to reproduce this?

Thanks again!
-Matt

Comment by Matt Cotter [ 16/Mar/16 ]

acm - I'm still looking into how this can happen, but the advice from bjori is reflected in this PR.

LeoZhao - can you try the branch in the PR and see if it fixes your issue? Thanks again for reporting this

Comment by Andrew Morrow (Inactive) [ 16/Mar/16 ]

matt.cotter -

Under what circumstances does mongoc_collection_find fail to return a cursor? I think that should inform our decision. If the case where it does not return a cursor really represents an error (one for which we can ask the underlying C driver what went wrong), I would lean towards an exception.

Comment by Matt Cotter [ 15/Mar/16 ]

Hi LeoZhao,

Does this print anything at all? I'm suspecting that the cursor failed from the very beginning.
edit: ^ never mind, the original description said this was not the case.

It looks like libmongoc's mongoc_collection_find can return a failed cursor, but we don't check for that in mongocxx collection find, nor do we offer a way to test this in the cursor class itself. acm - I'm thinking that we should do one of

  1. throw in find if the cursor fails
  2. return an optional cursor from find
  3. add an is_failed() or something similar to mongocxx::cursor

thoughts?

Comment by zy1989 [X] [ 15/Mar/16 ]

Following error will be throwed in the print of last document.
terminate called after throwing an instance of 'mongocxx::v_noabi::query_exception'
what(): Cannot advance a completed or failed cursor.: generic server error

Generated at Wed Feb 07 22:00:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.