示例#1
0
collection::collection(const database& database, void* collection)
    : _impl(stdx::make_unique<impl>(static_cast<mongoc_collection_t*>(collection),
                                    database.name(),
                                    database._get_impl().client_impl)) {}
collection::collection(const database& database, const std::string& collection_name)
    : _impl(bsoncxx::stdx::make_unique<impl>(
          libmongoc::database_get_collection(database._impl->database_t, collection_name.c_str()),
          database.name(), database._impl->client_impl, collection_name.c_str())) {
}
示例#3
0
collection::collection(const database& database, bsoncxx::string::view_or_value collection_name)
    : _impl(stdx::make_unique<impl>(
          libmongoc::database_get_collection(database._get_impl().database_t,
                                             collection_name.terminated().data()),
          database.name(),
          database._get_impl().client_impl)) {}
示例#4
0
    const std::string database_name("database");
    MOCK_CLIENT
    MOCK_DATABASE
    client mongo_client;

    SECTION("is created by a client") {
        bool called = false;
        get_database->interpose([&](mongoc_client_t* client, const char* c_name) {
            called = true;
            REQUIRE(database_name == c_name);
            return nullptr;
        });

        database obtained_database = mongo_client[database_name];
        REQUIRE(called);
        REQUIRE(obtained_database.name() == database_name);
    }
    SECTION("cleans up its underlying mongoc database on destruction") {
        bool destroy_called = false;

        database_destroy->interpose([&](mongoc_database_t* client) {
            destroy_called = true;
        });

        {
            database database = mongo_client["database"];
            REQUIRE(!destroy_called);
        }

        REQUIRE(destroy_called);
    }
collection::collection(const database& database, stdx::string_view collection_name,
                       void* collection)
    : _impl(stdx::make_unique<impl>(static_cast<mongoc_collection_t*>(collection), database.name(),
                                    database._impl->client_impl, collection_name.data())) {
}
collection::collection(const database& database, stdx::string_view collection_name)
    : _impl(stdx::make_unique<impl>(
          libmongoc::database_get_collection(database._impl->database_t, collection_name.data()),
          database.name(), database._impl->client_impl, collection_name.data())) {
}
示例#7
0
    }
    return expected_colls.empty();
}

TEST_CASE("A default constructed database is false-ish", "[database]") {
    instance::current();

    database d;
    REQUIRE(!d);
}

TEST_CASE("A default constructed database cannot perform operations", "[database]") {
    instance::current();

    database d;
    REQUIRE_THROWS_AS(d.name(), mongocxx::logic_error);
}

TEST_CASE("mongocxx::database copy constructor", "[database]") {
    instance::current();

    client client{uri{}};

    SECTION("constructing from valid") {
        database database_a = client["a"];
        database database_b{database_a};
        REQUIRE(database_b);
        REQUIRE(database_b.name() == stdx::string_view{"a"});
    }

    SECTION("constructing from invalid") {