本文整理汇总了C++中mongo::BSONObj类的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj类的具体用法?C++ BSONObj怎么用?C++ BSONObj使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BSONObj类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MongoNamespace
MongoCollectionInfo::MongoCollectionInfo(mongo::BSONObj stats)
{
_ns = MongoNamespace(QString::fromStdString(stats.getStringField("ns")));
_sizeBytes = stats.getIntField("size");
_count = stats.getIntField("count");
_storageSizeBytes = stats.getIntField("storageSize");
}
示例2: assert
//-----------------------------------------------------------------------------
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;
}
示例3: JSSleep
mongo::BSONObj JSSleep(const mongo::BSONObj &args){
assert( args.nFields() == 1 );
assert( args.firstElement().isNumber() );
int ms = int( args.firstElement().number() );
sleepms( ms );
return undefined_;
}
示例4: bigFiles
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;
}
}
示例5: return_bson
Datum return_bson(const mongo::BSONObj& b)
{
std::size_t bson_size = b.objsize() + VARHDRSZ;
bytea* new_bytea = (bytea *) palloc(bson_size);
SET_VARSIZE(new_bytea, bson_size);
std::memcpy(VARDATA(new_bytea), b.objdata(), b.objsize());
PG_RETURN_BYTEA_P(new_bytea);
}
示例6:
MongoCollectionInfo::MongoCollectionInfo(mongo::BSONObj stats):_ns(QString::fromStdString(stats.getStringField("ns")))
{
// if "size" and "storageSize" are of type Int32 or Int64, they
// will be converted to double by "numberDouble()" function.
_sizeBytes = stats.getField("size").numberDouble();
_storageSizeBytes = stats.getField("storageSize").numberDouble();
_count = stats.getIntField("count");
}
示例7: native_sleep
static BSONObj native_sleep( const mongo::BSONObj& args, void* data ) {
uassert( 16259,
"sleep takes a single numeric argument -- sleep(milliseconds)",
args.nFields() == 1 && args.firstElement().isNumber() );
sleepmillis( static_cast<long long>( args.firstElement().number() ) );
BSONObjBuilder b;
b.appendUndefined( "" );
return b.obj();
}
示例8: map
//-----------------------------------------------------------------------------
bool trial_c::map( Reveal::Core::trial_ptr& trial, mongo::BSONObj obj ) {
trial = Reveal::Core::trial_ptr( new Reveal::Core::trial_c() );
trial->scenario_id = obj.getField( "scenario_id" ).String();
trial->t = obj.getField( "t" ).Double();
model_c::fetch( trial, obj );
return true;
}
示例9: goodReplStatus
/** Good if one primary and rest secondaries and arbiters */
static bool goodReplStatus (mongo::BSONObj &info) {
if (!info.getField("ok").trueValue()) return false;
vector<mongo::BSONElement> ms = info.getField("members").Array();
bool primary = false;
for (unsigned i = 0; i < ms.size(); i++) {
int state = ms[i].Obj().getIntField("state");
if (state == 1) {primary = true; continue;}
if (state != 2 && state != 7) return false;
}
return primary;
}
示例10: fromjson
std::list<mongo::BSONObj> TransformComputable::compute_transform(mongo::BSONObj query, std::string collection)
{
//get positions in other frames
BSONObjBuilder query_other_frames;
query_other_frames.appendElements(query.removeField("frame").removeField("allow_tf"));
query_other_frames.append("frame", fromjson("{$exists:true}"));
QResCursor cur = robot_memory_->query(query_other_frames.obj(), collection);
//transform them is possible
std::list<mongo::BSONObj> res;
std::string target_frame = query.getField("frame").String();
while(cur->more())
{
BSONObj pos = cur->next();
if(pos.hasField("frame") && pos.hasField("translation") && pos.hasField("rotation"))
{
std::string src_frame = pos.getField("frame").String();
Time now(0, 0);
if(tf_->can_transform(target_frame.c_str(), src_frame.c_str(), now))
{
BSONObjBuilder res_pos;
std::vector<BSONElement> src_trans = pos.getField("translation").Array();
std::vector<BSONElement> src_rot = pos.getField("rotation").Array();
fawkes::tf::Transform pose_tf(fawkes::tf::Quaternion(src_rot[0].Double(), src_rot[1].Double(), src_rot[2].Double(), src_rot[3].Double()),
fawkes::tf::Vector3(src_trans[0].Double(), src_trans[1].Double(), src_trans[2].Double()));
fawkes::tf::Stamped<fawkes::tf::Pose> src_stamped_pose(pose_tf, Time(0, 0), src_frame.c_str());
fawkes::tf::Stamped<fawkes::tf::Pose> res_stamped_pose;
tf_->transform_pose(target_frame.c_str(), src_stamped_pose, res_stamped_pose);
res_pos.appendElements(pos.removeField("frame").removeField("translation").removeField("rotation").removeField("_id"));
res_pos.append("frame", target_frame);
res_pos.append("allow_tf", true);
BSONArrayBuilder arrb_trans;
arrb_trans.append(res_stamped_pose.getOrigin().x());
arrb_trans.append(res_stamped_pose.getOrigin().y());
arrb_trans.append(res_stamped_pose.getOrigin().z());
res_pos.append("translation", arrb_trans.arr());
BSONArrayBuilder arrb_rot;
arrb_rot.append(res_stamped_pose.getRotation().x());
arrb_rot.append(res_stamped_pose.getRotation().y());
arrb_rot.append(res_stamped_pose.getRotation().z());
arrb_rot.append(res_stamped_pose.getRotation().w());
res_pos.append("rotation", arrb_rot.arr());
res.push_back(res_pos.obj());
}
// else
// {
// logger_->log_info(name_, "Cant transform %s to %s", src_frame.c_str(), target_frame.c_str());
// }
}
}
return res;
}
示例11: DoHost
void Processer::DoHost(const std::string& grid,const std::string& cluster,mongo::BSONObj& host)
{
std::string host_id;
std::cout << host << std::endl;
if(host.hasField("host_ID") && host.hasField("heartbeat"))
{
//deal the record with host level
//do not need to cut it off
DBModules::iterator iter = db_modules_.begin();
for(;iter!=db_modules_.end();++iter)
{
iter->handler(host.objdata(),host.objsize(),NULL);
}
// host_id = host.getStringField("host_ID");
// std::vector<mongo::BSONElement> ele;
// host.elems(ele);
// for(int i=0;i<ele.size();i++)
// {
// if((!strcmp(ele[i].fieldName(),"host_ID")) ||
// (!strcmp(ele[i].fieldName(),"heartbeat")))
// {
// continue;
// }
// else
// {
// std::string ds_name = ele[i].fieldName();
// std::string path;
// if(grid!="")
// path = grid + '/' + cluster + '/' + host_id;
// else
// path = cluster + '/' + host_id;
// mongo::BSONObj obj = ele[i].wrap();
// std::cout << obj << std::endl;
// std::list<void(*)(const char*,int,const char*)>::iterator iter;
// iter = callback_[ds_name].begin();
// for(;iter!=callback_[ds_name].end();++iter)
// {
// (*iter)(obj.objdata(),obj.objsize(),path.c_str());
// }
// }
// }
}
else
{
std::stringstream oss;
oss << "This data is illegal! Drop!!";
LOG4CXX_WARN(log_,oss.str());
}
}
示例12: map
//-----------------------------------------------------------------------------
bool solution_c::map( Reveal::Core::solution_ptr& solution, mongo::BSONObj obj, Reveal::Core::solution_c::type_e type ) {
solution = Reveal::Core::solution_ptr( new Reveal::Core::solution_c( type ) );
if( type == Reveal::Core::solution_c::CLIENT )
solution->experiment_id = obj.getField( "experiment_id" ).String();
solution->scenario_id = obj.getField( "scenario_id" ).String();
solution->t = obj.getField( "t" ).Double();
if( type == Reveal::Core::solution_c::CLIENT )
solution->real_time = obj.getField( "real_time" ).Double();
model_c::fetch( solution, obj );
return true;
}
示例13: QUERY
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);
}
示例14: stitch_support_v1_update
stitch_support_v1_update(mongo::ServiceContext::UniqueClient client,
mongo::BSONObj updateExpr,
mongo::BSONArray arrayFilters,
stitch_support_v1_matcher* matcher,
stitch_support_v1_collator* collator)
: client(std::move(client)),
opCtx(this->client->makeOperationContext()),
updateExpr(updateExpr.getOwned()),
arrayFilters(arrayFilters.getOwned()),
matcher(matcher),
updateDriver(new mongo::ExpressionContext(
opCtx.get(), collator ? collator->collator.get() : nullptr)) {
std::vector<mongo::BSONObj> arrayFilterVector;
for (auto&& filter : this->arrayFilters) {
arrayFilterVector.push_back(filter.embeddedObject());
}
this->parsedFilters = uassertStatusOK(mongo::ParsedUpdate::parseArrayFilters(
arrayFilterVector, this->opCtx.get(), collator ? collator->collator.get() : nullptr));
// Initializing the update as single-document allows document-replacement updates.
bool multi = false;
updateDriver.parse(this->updateExpr, parsedFilters, multi);
uassert(51037,
"Updates with a positional operator require a matcher object.",
matcher || !updateDriver.needMatchDetails());
}
示例15: _objBsonToJson
void CMetadata::_objBsonToJson(rapidjson::Value& json, mongo::BSONObj& bson)
{
std::vector<mongo::BSONElement> values;
bson.elems(values);
for (uint i = 0; i<values.size(); ++i) {
this->_fieldBsonToJson(json, values[i].fieldName(), bson);
}
}