cursor collection::find(bsoncxx::document::view filter, const options::find& options) { using namespace bsoncxx; builder::stream::document filter_builder; scoped_bson_t filter_bson; scoped_bson_t projection(options.projection()); if (options.modifiers()) { filter_builder << "$query" << types::b_document{filter} << builder::stream::concatenate{ options.modifiers().value_or(document::view{})}; filter_bson.init_from_static(filter_builder.view()); } else { filter_bson.init_from_static(filter); } const mongoc_read_prefs_t* rp_ptr = NULL; if (options.read_preference()) { rp_ptr = options.read_preference()->_impl->read_preference_t; } return cursor(libmongoc::collection_find( _impl->collection_t, mongoc_query_flags_t(0), options.skip().value_or(0), options.limit().value_or(0), options.batch_size().value_or(0), filter_bson.bson(), projection.bson(), rp_ptr)); }
cursor collection::find(view_or_value filter, const options::find& options) { using namespace bsoncxx; builder::stream::document filter_builder; int query_flags = ::MONGOC_QUERY_NONE; scoped_bson_t filter_bson; scoped_bson_t projection{options.projection()}; filter_builder << "$query" << bsoncxx::types::b_document{filter}; if (options.modifiers()) { filter_builder << builder::stream::concatenate(*options.modifiers()); } if (options.sort()) { filter_builder << "$orderby" << bsoncxx::types::b_document{*options.sort()}; } if (options.max_time()) { filter_builder << "$maxTimeMS" << bsoncxx::types::b_int64{options.max_time()->count()}; } if (options.hint()) { filter_builder << builder::stream::concatenate(options.hint()->to_document()); } if (options.comment()) { filter_builder << "$comment" << *options.comment(); } if (options.cursor_type()) { if (*options.cursor_type() == cursor::type::k_non_tailable) { query_flags &= ~::MONGOC_QUERY_TAILABLE_CURSOR; } else if (*options.cursor_type() == cursor::type::k_tailable) { query_flags |= ::MONGOC_QUERY_TAILABLE_CURSOR; } else if (*options.cursor_type() == cursor::type::k_tailable_await) { query_flags |= ::MONGOC_QUERY_TAILABLE_CURSOR; query_flags |= ::MONGOC_QUERY_AWAIT_DATA; } else { throw logic_error{error_code::k_invalid_parameter}; } } filter_bson.init_from_static(filter_builder.view()); const mongoc_read_prefs_t* rp_ptr = NULL; if (options.read_preference()) { rp_ptr = options.read_preference()->_impl->read_preference_t; } auto mongoc_cursor = libmongoc::collection_find( _get_impl().collection_t, static_cast<::mongoc_query_flags_t>(query_flags), options.skip().value_or(0), options.limit().value_or(0), options.batch_size().value_or(0), filter_bson.bson(), projection.bson(), rp_ptr); if (options.max_await_time()) { const auto count = options.max_await_time()->count(); if ((count < 0) || (count >= std::numeric_limits<std::uint32_t>::max())) throw logic_error{error_code::k_invalid_parameter}; libmongoc::cursor_set_max_await_time_ms(mongoc_cursor, static_cast<std::uint32_t>(count)); } return cursor{mongoc_cursor}; }
cursor collection::find(view_or_value filter, const options::find& options) { using namespace bsoncxx; builder::stream::document filter_builder; scoped_bson_t filter_bson; scoped_bson_t projection{options.projection()}; filter_builder << "$query" << bsoncxx::types::b_document{filter}; if (options.modifiers()) { filter_builder << builder::stream::concatenate(*options.modifiers()); } if (options.sort()) { filter_builder << "$orderby" << bsoncxx::types::b_document{*options.sort()}; } if (options.max_time()) { filter_builder << "$maxTimeMS" << options.max_time()->count(); } if (options.hint()) { filter_builder << builder::stream::concatenate(options.hint()->to_document()); } filter_bson.init_from_static(filter_builder.view()); const mongoc_read_prefs_t* rp_ptr = NULL; if (options.read_preference()) { rp_ptr = options.read_preference()->_impl->read_preference_t; } auto mongoc_cursor = libmongoc::collection_find( _get_impl().collection_t, mongoc_query_flags_t(0), options.skip().value_or(0), options.limit().value_or(0), options.batch_size().value_or(0), filter_bson.bson(), projection.bson(), rp_ptr); if (options.max_await_time()) { const auto count = options.max_await_time()->count(); if ((count < 0) || (count >= std::numeric_limits<std::uint32_t>::max())) throw logic_error{make_error_code(error_code::k_invalid_parameter)}; libmongoc::cursor_set_max_await_time_ms(mongoc_cursor, static_cast<std::uint32_t>(count)); } return cursor{mongoc_cursor}; }