[CXX-604] Documentation for mongocxx::collection::find_one doesn't specify what happens if the document isn't found Created: 25/May/15  Updated: 16/Nov/15  Resolved: 13/Nov/15

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

Type: Improvement Priority: Minor - P4
Reporter: Scott Deerwester Assignee: Matt Cotter
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Any


Epic Link: C++11 Driver MongoDB 3.2

 Description   

The documentation for mongocxx::collection::find_one says that it throws a mongocxx::exception::query exception if the query fails. It's not clear whether failure is meant to include the case where no documents are returned. It appears that the actual behavior is to return an instance of the return type with the value set to nullopt. This needs to be described. An example of use would also be useful and welcome.



 Comments   
Comment by Matt Cotter [ 13/Nov/15 ]

Hi Scott,

We think the docs are pretty much fine as is. When we say that the return is "[a]n optional document", we mean that (as you've pointed out) the find_one command may not be able to return a document because no documents match. In that case, the return will be stdx::nullopt (just as you've deduced). This will only throw if the command itself errors (ex: an unauthenticated user tries a find).

We're going to close this, but please feel free to re-open if you need!

-Matt

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