当前位置: 首页>>代码示例>>C++>>正文


C++ MongoDatabase::databaseName方法代码示例

本文整理汇总了C++中MongoDatabase::databaseName方法的典型用法代码示例。如果您正苦于以下问题:C++ MongoDatabase::databaseName方法的具体用法?C++ MongoDatabase::databaseName怎么用?C++ MongoDatabase::databaseName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDatabase的用法示例。


在下文中一共展示了MongoDatabase::databaseName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: toCjson

std::string CjsonExporter::toCjson(const mongo::BSONObj &mongoChemObj)
{
  // Follow the database link and convert to CJSON.
  MongoDatabase *db = MongoDatabase::instance();
  if (!db)
    return "";

  mongo::BSONObj structure = mongoChemObj.getObjectField("3dStructure");
  if (!structure.hasField("$ref") || !structure.hasField("$id")
      || !structure.getField("$id").isSimpleType()) {
    return "";
  }
  std::auto_ptr<mongo::DBClientCursor> cursor =
      db->query(db->databaseName() + "." + structure.getStringField("$ref"),
                QUERY("_id" << structure.getField("$id").OID()), 1);
  mongo::BSONObj object;
  if (cursor->more())
    object = cursor->next();
  else
    return "";

  std::vector<std::string> toCopy;
  toCopy.push_back("name");
  toCopy.push_back("inchi");
  toCopy.push_back("formula");
  toCopy.push_back("properties");
  mongo::BSONObjBuilder builder;

  for (size_t i = 0; i < toCopy.size(); i++) {
    mongo::BSONElement field = mongoChemObj.getField(toCopy[i]);
    if (!field.eoo())
      builder.append(field);
  }
  toCopy.clear();
  toCopy.push_back("atoms");
  toCopy.push_back("bonds");
  for (size_t i = 0; i < toCopy.size(); i++) {
    mongo::BSONElement field = object.getField(toCopy[i]);
    if (!field.eoo())
      builder.append(field);
  }

  // Add the chemical JSON version field.
  builder.append("chemical json", 0);

  mongo::BSONObj obj = builder.obj();

  return obj.jsonString(mongo::Strict);
}
开发者ID:OpenChemistry,项目名称:mongochem,代码行数:49,代码来源:cjsonexporter.cpp

示例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();
}
开发者ID:OpenChemistry,项目名称:mongochem,代码行数:24,代码来源:computationalresultsmodel.cpp


注:本文中的MongoDatabase::databaseName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。