class collection database::create_view(bsoncxx::string::view_or_value name, bsoncxx::string::view_or_value view_on, const options::create_view& options) { bsoncxx::builder::basic::document options_builder; options_builder.append(kvp("viewOn", view_on)); if (options.collation()) { options_builder.append(kvp("collation", *options.collation())); } if (options.pipeline()) { options_builder.append(kvp("pipeline", options.pipeline()->view_array())); } if (options.write_concern()) { options_builder.append(kvp("writeConcern", options.write_concern()->to_document())); } libbson::scoped_bson_t opts_bson{options_builder.view()}; bson_error_t error; auto result = libmongoc::database_create_collection( _get_impl().database_t, name.terminated().data(), opts_bson.bson(), &error); if (!result) { throw_exception<operation_exception>(error); } return mongocxx::collection(*this, result); }
class collection database::create_view(bsoncxx::string::view_or_value name, bsoncxx::string::view_or_value view_on, const options::create_view& options) { document options_builder{}; options_builder << "viewOn" << view_on; if (options.collation()) { options_builder << "collation" << *options.collation(); } if (options.pipeline()) { options_builder << "pipeline" << options.pipeline()->view_array(); } libbson::scoped_bson_t opts_bson{options_builder.view()}; bson_error_t error; auto result = libmongoc::database_create_collection( _get_impl().database_t, name.terminated().data(), opts_bson.bson(), &error); if (!result) { throw_exception<operation_exception>(error); } return mongocxx::collection(*this, result); }