2

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/

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Ahmed Shahid
  • 284
  • 3
  • 14
  • 2
    Is the link to 1.2.0 the old or the new version? What was the old version you were using? What is the new version you are trying to use? – Jonathan Leffler Dec 30 '15 at 06:35
  • The link is for the new Driver. Which is C 1.2. The older version was 0.8. Here is the link to the repo for the old driver, https://github.com/mongodb/mongo-c-driver-legacy/blob/master/README.md – Ahmed Shahid Dec 30 '15 at 07:02

1 Answers1

2

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.

Vality
  • 6,577
  • 3
  • 27
  • 48