Search code examples
cmongodbmongo-c-driver

Is there an equivalent of mongo_find_one() in the new Mongo C driver


In the legacy Mongo C driver there was a a function mongo_find_one, which was used to find a single document in a MongoDB server.

MONGO_EXPORT int mongo_find_one( mongo *conn, const char *ns, const bson *query,const bson *fields, bson *out );

Is there a similar function in the new Mongo driver. I have been using the following documentation but was not able to find anything that is equivalent.

http://api.mongodb.org/c/1.2.0/


Solution

  • This is likely an unsatisfying answer, but it does not appear there is a direct equivalent of the mongo_find_one function in version 1.2.0.

    It should not however be particularly difficult to build a function with similar semantics using a cursor and taking only a single element from it and discarding the rest.