As seen here https://github.com/mongodb/mongo-c-driver/blob/7f1dd3630d6bb4b8d5db4c2b865c328acd170012/src/mongoc/mongoc-gridfs.c#L236 ,
there is no code that sets the limit = 1 option for the call to _mongoc_gridfs_file_list_new_with_opts().
As a consequence, the code will always fetch all results (unless explicitly overridden by the user of course) from the server whereas it does in fact use only the first one as a return value. This in turn eliminates any performance gain one could expect from using this function.
One proposed solution would be to always set the limit = 1 option before calling _mongoc_gridfs_file_list_new_with_opts(). For example:
... bson_t new_opts; bson_init(&new_opts); if (opts) bson_copy_to_excluding_noinit(opts, &new_opts, "limit", (char *)NULL); BSON_APPEND_INT32(&new_opts, "limit", 1); list = _mongoc_gridfs_file_list_new_with_opts (gridfs, filter, new_opts); ...