本文整理汇总了C++中mongo::BSONObj::getObjectField方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::getObjectField方法的具体用法?C++ BSONObj::getObjectField怎么用?C++ BSONObj::getObjectField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo::BSONObj
的用法示例。
在下文中一共展示了BSONObj::getObjectField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fetch
//-----------------------------------------------------------------------------
bool joint_c::fetch( Reveal::Core::joint_ptr joint, mongo::BSONObj bson ) {
assert( joint );
joint->id = bson.getField( FIELD_ID ).String();
mongo::BSONObj bson_q = bson.getObjectField( FIELD_STATE_POSITION );
std::vector<mongo::BSONElement> v_q;
bson_q.elems( v_q );
for( unsigned i = 0; i < v_q.size(); i++ )
joint->state.q( i, v_q[i].Double() );
mongo::BSONObj bson_dq = bson.getObjectField( FIELD_STATE_VELOCITY );
std::vector<mongo::BSONElement> v_dq;
bson_dq.elems( v_dq );
for( unsigned i = 0; i < v_dq.size(); i++ )
joint->state.dq( i, v_dq[i].Double() );
mongo::BSONObj bson_u = bson.getObjectField( FIELD_CONTROL );
std::vector<mongo::BSONElement> v_u;
bson_u.elems( v_u );
for( unsigned i = 0; i < v_u.size(); i++ )
joint->control.u( i, v_u[i].Double() );
return true;
}
示例2:
RepoBSON::RepoBSON(
const mongo::BSONObj &obj,
const std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> &binMapping)
: mongo::BSONObj(obj),
bigFiles(binMapping)
{
std::vector<std::pair<std::string, std::string>> existingFiles;
if (bigFiles.size() > 0)
{
mongo::BSONObjBuilder builder, arrbuilder;
for (const auto & pair : bigFiles)
{
//append field name :file name
arrbuilder << pair.first << pair.second.first;
}
if (obj.hasField(REPO_LABEL_OVERSIZED_FILES))
{
arrbuilder.appendElementsUnique(obj.getObjectField(REPO_LABEL_OVERSIZED_FILES));
}
builder.append(REPO_LABEL_OVERSIZED_FILES, arrbuilder.obj());
builder.appendElementsUnique(obj);
*this = builder.obj();
bigFiles = binMapping;
}
}
示例3: 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);
}