のWindows 7、msys2、コンパイラMinGWのは、C++コードからのMongoDBインスタンスに接続しようとすると、C++コード
からのMongoDBに接続できません。次のコマンドを使用してmongod
を実行している:私は通常mongo
によって及びRobomongoに、このデータベースに接続することができます
mongod --dbpath ./dev-db --bind_ip 127.0.0.1 --port 27017
。
私は正常にコンパイルし、最後に安定したMongo C++ドライバをインストールしました。私は公式tutorialから取るコード:
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
mongocxx::uri uri("mongodb://127.0.0.1:27017");
mongocxx::client conn{uri};
auto db = conn["test"];
bsoncxx::document::value restaurant_doc =
document{} << "address" << open_document << "street"
<< "2 Avenue"
<< "zipcode"
<< "10075"
<< "building"
<< "1480"
<< "coord" << open_array << -73.9557413 << 40.7720266 << close_array
<< close_document << "borough"
<< "Manhattan"
<< "cuisine"
<< "Italian"
<< "grades" << open_array << open_document << "date"
<< bsoncxx::types::b_date{std::chrono::milliseconds{12323}} << "grade"
<< "A"
<< "score" << 11 << close_document << open_document << "date"
<< bsoncxx::types::b_date{std::chrono::milliseconds{121212}} << "grade"
<< "B"
<< "score" << 17 << close_document << close_array << "name"
<< "Vella"
<< "restaurant_id"
<< "41704620" << finalize;
auto res = db["restaurants"].insert_one(std::move(restaurant_doc))
そして、これは、次のエラー提供:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of 'mongocxx::v_noabi::bulk_write_exception'
what(): No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve '127.0.0.1']: generic server error
どのように私はこの問題を回避して、データベースに接続することができますか?
localhostを使用しているのは役に立ちません。 '[localhost ']を解決できませんでした。 – Serbin