本文整理汇总了C++中MongoDatabase::connection方法的典型用法代码示例。如果您正苦于以下问题:C++ MongoDatabase::connection方法的具体用法?C++ MongoDatabase::connection怎么用?C++ MongoDatabase::connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDatabase
的用法示例。
在下文中一共展示了MongoDatabase::connection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showLogFile
void ComputationalResultsTableView::showLogFile()
{
MongoDatabase *db = MongoDatabase::instance();
mongo::GridFS fs(*db->connection(), "chem", "fs");
mongo::BSONObj *obj =
static_cast<mongo::BSONObj *>(currentIndex().internalPointer());
if (obj) {
const char *file_name = obj->getStringField("log_file");
mongo::GridFile file = fs.findFile(file_name);
if (!file.exists()) {
QMessageBox::critical(this,
"Error",
"Failed to load output file.");
return;
}
// load file into a buffer
std::stringstream stream;
file.write(stream);
QTextEdit *viewer = new QTextEdit(this);
viewer->resize(500, 600);
viewer->setWindowFlags(Qt::Dialog);
viewer->setWindowTitle(file_name);
viewer->setReadOnly(true);
std::string file_data_string = stream.str();
viewer->setText(file_data_string.c_str());
viewer->show();
}
else {
QMessageBox::critical(this,
"Error",
"Failed to load output file.");
}
}
示例2: setQuery
void ComputationalResultsModel::setQuery(const mongo::Query &query)
{
beginInsertRows(QModelIndex(), 0, rowCount(QModelIndex()));
m_objects.clear();
MongoDatabase *db = MongoDatabase::instance();
try {
std::string collection = db->databaseName();
std::auto_ptr<mongo::DBClientCursor> cursor =
db->connection()->query(collection + ".quantum", query);
// Let's read in the results, but limit to 1000 in case of bad queries.
int i(0);
while (cursor->more() && ++i < 1000)
m_objects.push_back(cursor->next().copy());
}
catch (mongo::SocketException &e) {
std::cerr << "Failed to query MongoDB: " << e.what() << std::endl;
}
endInsertRows();
}