本文整理汇总了C++中BSONObjBuilder::appendNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObjBuilder::appendNumber方法的具体用法?C++ BSONObjBuilder::appendNumber怎么用?C++ BSONObjBuilder::appendNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObjBuilder
的用法示例。
在下文中一共展示了BSONObjBuilder::appendNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: appendInfo
void DBConnectionPool::appendInfo( BSONObjBuilder& b ) {
int avail = 0;
long long created = 0;
map<ConnectionString::ConnectionType,long long> createdByType;
BSONObjBuilder bb( b.subobjStart( "hosts" ) );
{
scoped_lock lk( _mutex );
for ( PoolMap::iterator i=_pools.begin(); i!=_pools.end(); ++i ) {
if ( i->second.numCreated() == 0 )
continue;
string s = str::stream() << i->first.ident << "::" << i->first.timeout;
BSONObjBuilder temp( bb.subobjStart( s ) );
temp.append( "available" , i->second.numAvailable() );
temp.appendNumber( "created" , i->second.numCreated() );
temp.done();
avail += i->second.numAvailable();
created += i->second.numCreated();
long long& x = createdByType[i->second.type()];
x += i->second.numCreated();
}
}
bb.done();
// Always report all replica sets being tracked
set<string> replicaSets = ReplicaSetMonitor::getAllTrackedSets();
BSONObjBuilder setBuilder( b.subobjStart( "replicaSets" ) );
for ( set<string>::iterator i=replicaSets.begin(); i!=replicaSets.end(); ++i ) {
string rs = *i;
ReplicaSetMonitorPtr m = ReplicaSetMonitor::get( rs );
if ( ! m ) {
warning() << "no monitor for set: " << rs << endl;
continue;
}
BSONObjBuilder temp( setBuilder.subobjStart( rs ) );
m->appendInfo( temp );
temp.done();
}
setBuilder.done();
{
BSONObjBuilder temp( bb.subobjStart( "createdByType" ) );
for ( map<ConnectionString::ConnectionType,long long>::iterator i=createdByType.begin(); i!=createdByType.end(); ++i ) {
temp.appendNumber( ConnectionString::typeToString( i->first ) , i->second );
}
temp.done();
}
b.append( "totalAvailable" , avail );
b.appendNumber( "totalCreated" , created );
}
示例2: addToBsonArray
void DocumentSourceSort::addToBsonArray(BSONArrayBuilder *pBuilder, bool explain) const {
if (explain) { // always one obj for combined $sort + $limit
BSONObjBuilder sortObj (pBuilder->subobjStart());
BSONObjBuilder insides (sortObj.subobjStart(sortName));
BSONObjBuilder sortKey (insides.subobjStart("sortKey"));
sortKeyToBson(&sortKey, false);
sortKey.doneFast();
if (explain && limitSrc) {
insides.appendNumber("limit", limitSrc->getLimit());
}
insides.doneFast();
sortObj.doneFast();
}
else { // one obj for $sort + maybe one obj for $limit
{
BSONObjBuilder sortObj (pBuilder->subobjStart());
BSONObjBuilder insides (sortObj.subobjStart(sortName));
sortKeyToBson(&insides, false);
insides.doneFast();
sortObj.doneFast();
}
if (limitSrc) {
limitSrc->addToBsonArray(pBuilder, explain);
}
}
}
示例3: append
void OpDebug::append(const CurOp& curop,
const SingleThreadedLockStats& lockStats,
BSONObjBuilder& b) const {
const size_t maxElementSize = 50 * 1024;
b.append( "op" , iscommand ? "command" : opToString( op ) );
b.append( "ns" , ns.toString() );
if (!query.isEmpty()) {
appendAsObjOrString(iscommand ? "command" : "query", query, maxElementSize, &b);
}
else if (!iscommand && curop.haveQuery()) {
appendAsObjOrString("query", curop.query(), maxElementSize, &b);
}
if (!updateobj.isEmpty()) {
appendAsObjOrString("updateobj", updateobj, maxElementSize, &b);
}
const bool moved = (nmoved >= 1);
OPDEBUG_APPEND_NUMBER( cursorid );
OPDEBUG_APPEND_NUMBER( ntoreturn );
OPDEBUG_APPEND_NUMBER( ntoskip );
OPDEBUG_APPEND_BOOL( exhaust );
OPDEBUG_APPEND_NUMBER( nscanned );
OPDEBUG_APPEND_NUMBER( nscannedObjects );
OPDEBUG_APPEND_BOOL( idhack );
OPDEBUG_APPEND_BOOL( scanAndOrder );
OPDEBUG_APPEND_BOOL( moved );
OPDEBUG_APPEND_NUMBER( nmoved );
OPDEBUG_APPEND_NUMBER( nMatched );
OPDEBUG_APPEND_NUMBER( nModified );
OPDEBUG_APPEND_NUMBER( ninserted );
OPDEBUG_APPEND_NUMBER( ndeleted );
OPDEBUG_APPEND_BOOL( fastmod );
OPDEBUG_APPEND_BOOL( fastmodinsert );
OPDEBUG_APPEND_BOOL( upsert );
OPDEBUG_APPEND_BOOL( cursorExhausted );
OPDEBUG_APPEND_NUMBER( keyUpdates );
OPDEBUG_APPEND_NUMBER( writeConflicts );
b.appendNumber("numYield", curop.numYields());
{
BSONObjBuilder locks(b.subobjStart("locks"));
lockStats.report(&locks);
}
if (!exceptionInfo.empty()) {
exceptionInfo.append(b, "exception", "exceptionCode");
}
OPDEBUG_APPEND_NUMBER( nreturned );
OPDEBUG_APPEND_NUMBER( responseLength );
b.append( "millis" , executionTime );
execStats.append(b, "execStats");
}
示例4: appendInfo
void CursorCache::appendInfo(BSONObjBuilder& result) const {
stdx::lock_guard<stdx::mutex> lk(_mutex);
result.append("sharded", static_cast<int>(cursorStatsMultiTarget.get()));
result.appendNumber("shardedEver", _shardedTotal);
result.append("refs", static_cast<int>(cursorStatsSingleTarget.get()));
result.append("totalOpen", static_cast<int>(cursorStatsTotalOpen.get()));
}
示例5: run
virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
/* currently request to arbiter is (somewhat arbitrarily) an ismaster request that is not
authenticated.
*/
if ( cmdObj["forShell"].trueValue() )
lastError.disableForCommand();
appendReplicationInfo(result, 0);
result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes);
result.appendDate("localTime", jsTime());
result.append("maxWireVersion", maxWireVersion);
result.append("minWireVersion", minWireVersion);
return true;
}
示例6: run
bool run(const string& dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
result << "version" << versionString << "gitVersion" << gitVersion() << "sysInfo" << sysInfo();
result << "bits" << ( sizeof( int* ) == 4 ? 32 : 64 );
result.appendBool( "debug" , debug );
result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
return true;
}
示例7: run
virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
string p = cmdObj.firstElement().String();
if ( p == "*" ) {
vector<string> names;
RamLog::getNames( names );
BSONArrayBuilder arr;
for ( unsigned i=0; i<names.size(); i++ ) {
arr.append( names[i] );
}
result.appendArray( "names" , arr.arr() );
}
else {
RamLog* ramlog = RamLog::getIfExists(p);
if ( ! ramlog ) {
errmsg = str::stream() << "no RamLog named: " << p;
return false;
}
RamLog::LineIterator rl(ramlog);
result.appendNumber( "totalLinesWritten", rl.getTotalLinesWritten() );
BSONArrayBuilder arr( result.subarrayStart( "log" ) );
while (rl.more())
arr.append(rl.next());
arr.done();
}
return true;
}
示例8: generateSection
BSONObj IndexCounters::generateSection(const BSONElement& configElement) const {
if ( ! _memSupported ) {
return BSON( "note" << "not supported on this platform" );
}
BSONObjBuilder bb;
bb.appendNumber( "accesses" , _btreeAccesses );
bb.appendNumber( "hits" , _btreeMemHits );
bb.appendNumber( "misses" , _btreeMemMisses );
bb.append( "resets" , _resets );
bb.append( "missRatio" , (_btreeAccesses ? (_btreeMemMisses / (double)_btreeAccesses) : 0) );
return bb.obj();
}
示例9: appendInfo
void CursorCache::appendInfo( BSONObjBuilder& result ) const {
scoped_lock lk( _mutex );
result.append( "sharded" , (int)_cursors.size() );
result.appendNumber( "shardedEver" , _shardedTotal );
result.append( "refs" , (int)_refs.size() );
result.append( "totalOpen" , (int)(_cursors.size() + _refs.size() ) );
}
示例10: appendSelf
bool LastError::appendSelf(BSONObjBuilder& b, bool blankErr) const {
if (!_valid) {
if (blankErr)
b.appendNull("err");
b.append("n", 0);
return false;
}
if (_msg.empty()) {
if (blankErr) {
b.appendNull("err");
}
} else {
b.append("err", _msg);
}
if (_code) {
b.append("code", _code);
b.append("codeName", ErrorCodes::errorString(ErrorCodes::Error(_code)));
}
if (_updatedExisting != NotUpdate)
b.appendBool("updatedExisting", _updatedExisting == True);
if (!_upsertedId.isEmpty()) {
b.append(_upsertedId[kUpsertedFieldName]);
}
b.appendNumber("n", _nObjects);
return !_msg.empty();
}
示例11: createBSONMetadataDocument
BSONObj createBSONMetadataDocument(const BSONObj& metadata, Date_t date) {
BSONObjBuilder builder;
builder.appendDate(kFTDCIdField, date);
builder.appendNumber(kFTDCTypeField, static_cast<int>(FTDCType::kMetadata));
builder.appendObject(kFTDCDocField, metadata.objdata(), metadata.objsize());
return builder.obj();
}
示例12: run
bool run(OperationContext* txn, const string& dbname , BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
DBDirectClient db(txn);
BSONElement e = jsobj.firstElement();
string toDeleteNs = dbname + '.' + e.valuestr();
LOG(0) << "CMD: reIndex " << toDeleteNs << endl;
Lock::DBWrite dbXLock(txn->lockState(), dbname);
WriteUnitOfWork wunit(txn->recoveryUnit());
Client::Context ctx(txn, toDeleteNs);
Collection* collection = ctx.db()->getCollection( txn, toDeleteNs );
if ( !collection ) {
errmsg = "ns not found";
return false;
}
BackgroundOperation::assertNoBgOpInProgForNs( toDeleteNs );
std::vector<BSONObj> indexesInProg = stopIndexBuilds(txn, ctx.db(), jsobj);
vector<BSONObj> all;
{
vector<string> indexNames;
collection->getCatalogEntry()->getAllIndexes( &indexNames );
for ( size_t i = 0; i < indexNames.size(); i++ ) {
const string& name = indexNames[i];
BSONObj spec = collection->getCatalogEntry()->getIndexSpec( name );
all.push_back( spec.getOwned() );
}
}
result.appendNumber( "nIndexesWas", all.size() );
Status s = collection->getIndexCatalog()->dropAllIndexes(txn, true);
if ( !s.isOK() ) {
errmsg = "dropIndexes failed";
return appendCommandStatus( result, s );
}
for ( size_t i = 0; i < all.size(); i++ ) {
BSONObj o = all[i];
LOG(1) << "reIndex ns: " << toDeleteNs << " index: " << o << endl;
Status s = collection->getIndexCatalog()->createIndex(txn, o, false);
if ( !s.isOK() )
return appendCommandStatus( result, s );
}
result.append( "nIndexes", (int)all.size() );
result.append( "indexes", all );
IndexBuilder::restoreIndexes(indexesInProg);
wunit.commit();
return true;
}
示例13: getExtraInfo
void ProcessInfo::getExtraInfo( BSONObjBuilder& info ) {
// [dm] i don't think mallinfo works. (64 bit.) ??
struct mallinfo malloc_info = mallinfo(); // structure has same name as function that returns it. (see malloc.h)
info.append("heap_usage_bytes", malloc_info.uordblks/*main arena*/ + malloc_info.hblkhd/*mmap blocks*/);
//docs claim hblkhd is included in uordblks but it isn't
LinuxProc p(_pid);
info.appendNumber("page_faults", static_cast<long long>(p._maj_flt) );
}
示例14:
BSONObj CollectionBulkLoaderImpl::Stats::toBSON() const {
BSONObjBuilder bob;
bob.appendDate("startBuildingIndexes", startBuildingIndexes);
bob.appendDate("endBuildingIndexes", endBuildingIndexes);
auto indexElapsed = endBuildingIndexes - startBuildingIndexes;
long long indexElapsedMillis = duration_cast<Milliseconds>(indexElapsed).count();
bob.appendNumber("indexElapsedMillis", indexElapsedMillis);
return bob.obj();
}
示例15: info
BSONObj CurOp::info() {
BSONObjBuilder b;
b.append("opid", _opNum);
bool a = _active && _start;
b.append("active", a);
if( a ) {
b.append("secs_running", elapsedSeconds() );
}
b.append( "op" , opToString( _op ) );
b.append("ns", _ns);
if (_op == dbInsert) {
_query.append(b, "insert");
}
else {
_query.append(b , "query");
}
if( !_remote.empty() ) {
b.append("client", _remote.toString());
}
if ( _client ) {
b.append( "desc" , _client->desc() );
if ( _client->_threadId.size() )
b.append( "threadId" , _client->_threadId );
if ( _client->_connectionId )
b.appendNumber( "connectionId" , _client->_connectionId );
_client->_ls.reportState(b);
}
if ( ! _message.empty() ) {
if ( _progressMeter.isActive() ) {
StringBuilder buf;
buf << _message.toString() << " " << _progressMeter.toString();
b.append( "msg" , buf.str() );
BSONObjBuilder sub( b.subobjStart( "progress" ) );
sub.appendNumber( "done" , (long long)_progressMeter.done() );
sub.appendNumber( "total" , (long long)_progressMeter.total() );
sub.done();
}
else {
b.append( "msg" , _message.toString() );
}
}
if( killPending() )
b.append("killPending", true);
b.append( "numYields" , _numYields );
b.append( "lockStats" , _lockStat.report() );
return b.obj();
}