作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试将 MongoDB 与 QT c++ 连接起来。我编写了运行时没有任何错误的简单应用程序。
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
try
{
connectMongo();
qDebug() << "Connection done";
}
catch (const mongo::DBException &e)
{
qDebug() << "Failed : " << e.what();
}
}
void MainWindow::connectMongo()
{
mongo::DBClientConnection c;
c.connect("127.0.0.1");
}
但是,当我键入“127.0.0.1”或“localhost”时,它无法连接,并且在调试窗口中显示:
The program has unexpectedly finished.
当我键入另一个值时,例如 c.connect("0.0.0.0");
它进入 catch block ,异常是:
Failed : can't connect couldn't connect to server 0.0.0.0:27017
据我所知,它使用正确的端口号工作,该端口号在 MongoDB API 上描述为默认值。那么为什么我不能使用 MongoDB 并且无法连接它呢?
这是服务的输出;
[mg@mg-CentOS ~]$ service mongod status
mongod (pid 4151) is running...
最佳答案
QxOrm library现在支持 MongoDB 数据库。这是文档的链接:https://www.qxorm.com/qxorm_en/manual.html#manual_95
关于c++ - 如何将 MongoDB 与 Qt C++ 连接起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31586638/
我是一名优秀的程序员,十分优秀!