예제 #1
0
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));
}
예제 #2
0
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());
    }

    if (options.comment()) {
        filter_builder << "$comment" << *options.comment();
    }

    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};
}
예제 #3
0
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()) {
        libmongoc::cursor_set_max_await_time_ms(mongoc_cursor, (*options.max_await_time()).count());
    }

    return cursor{mongoc_cursor};
}