mongodbmongo-c-driver

Is there a findOne operation in the Mongo C driver?


MongoDB implements afindOne() collection operation.

However, looking into the collection operations available in the Mongo C driver I haven't found it there. It's a bit surprising, as other drivers implements it (such as the C++ driver).

Interestingly, I have found in the Mongo C driver code repository a kind of implementation for a findOne function. However it seems it is in a part of the code related with the tets...

Thus, is the Mongo C driver providing a findOne() operation? Or do I need to implement it myself (maybe using mongoc_collection_find_with_opts setting limit to 1)?


Solution

  • The function you located is indeed used for executing tests (cross-driver ones) which do contain a findOne operation.

    Based on this I would say the C driver doesn't provide a findOne operation and you are meant to use something like the find_one function you found to get a single document out of the cursor returned from mongoc_collection_find_with_opts.