Exemple #1
0
class collection database::create_collection(stdx::string_view name,
                                             const options::create_collection& options) {
    bson_error_t error;

    libbson::scoped_bson_t opts_bson{options.to_document()};
    auto result = libmongoc::database_create_collection(_get_impl().database_t, name.data(),
                                                        opts_bson.bson(), &error);

    if (!result) {
        throw_exception<operation_exception>(error);
    }

    return mongocxx::collection(*this, static_cast<void*>(result));
}
    SECTION("Can be exported to a document") {
        auto rule = builder::stream::document{} << "brain" << open_document << "$exists" << true
                                                << close_document << finalize;

        validation_criteria validation;
        validation.rule(rule.view());
        validation.level(validation_criteria::validation_level::k_strict);

        cc.validation_criteria(validation);
        cc.capped(true);
        cc.size(256);
        cc.max(100);
        cc.no_padding(true);

        auto doc = cc.to_document();
        document::view doc_view{doc.view()};

        // capped field is set to true
        document::element capped{doc_view["capped"]};
        REQUIRE(capped);
        REQUIRE(capped.type() == type::k_bool);
        REQUIRE(capped.get_bool() == true);

        // autoIndexId should not be set
        document::element autoIndex{doc_view["autoIndexId"]};
        REQUIRE(!autoIndex);

        // size should be set
        document::element size{doc_view["size"]};
        REQUIRE(size);