本文整理汇总了C++中BSONArrayBuilder::done方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONArrayBuilder::done方法的具体用法?C++ BSONArrayBuilder::done怎么用?C++ BSONArrayBuilder::done使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONArrayBuilder
的用法示例。
在下文中一共展示了BSONArrayBuilder::done方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeMetadataFile
void writeMetadataFile( const string coll, boost::filesystem::path outputFile,
map<string, BSONObj> options, multimap<string, BSONObj> indexes ) {
toolInfoLog() << "\tMetadata for " << coll << " to " << outputFile.string() << std::endl;
bool hasOptions = options.count(coll) > 0;
bool hasIndexes = indexes.count(coll) > 0;
BSONObjBuilder metadata;
if (hasOptions) {
metadata << "options" << options.find(coll)->second;
}
if (hasIndexes) {
BSONArrayBuilder indexesOutput (metadata.subarrayStart("indexes"));
// I'd kill for C++11 auto here...
const pair<multimap<string, BSONObj>::iterator, multimap<string, BSONObj>::iterator>
range = indexes.equal_range(coll);
for (multimap<string, BSONObj>::iterator it=range.first; it!=range.second; ++it) {
indexesOutput << it->second;
}
indexesOutput.done();
}
ofstream file (outputFile.string().c_str());
uassert(15933, "Couldn't open file: " + outputFile.string(), file.is_open());
file << metadata.done().jsonString();
}
示例2: run
bool Pipeline::run(BSONObjBuilder &result, string &errmsg) {
massert(16600, "should not have an empty pipeline",
!sources.empty());
/* chain together the sources we found */
DocumentSource* prevSource = sources.front().get();
for(SourceContainer::iterator iter(sources.begin() + 1),
listEnd(sources.end());
iter != listEnd;
++iter) {
intrusive_ptr<DocumentSource> pTemp(*iter);
pTemp->setSource(prevSource);
prevSource = pTemp.get();
}
/*
Iterate through the resulting documents, and add them to the result.
We do this even if we're doing an explain, in order to capture
the document counts and other stats. However, we don't capture
the result documents for explain.
*/
if (explain) {
if (!pCtx->getInRouter())
writeExplainShard(result);
else {
writeExplainMongos(result);
}
}
else {
// the array in which the aggregation results reside
// cant use subArrayStart() due to error handling
BSONArrayBuilder resultArray;
DocumentSource* finalSource = sources.back().get();
for(bool hasDoc = !finalSource->eof(); hasDoc; hasDoc = finalSource->advance()) {
Document pDocument(finalSource->getCurrent());
/* add the document to the result set */
BSONObjBuilder documentBuilder (resultArray.subobjStart());
pDocument->toBson(&documentBuilder);
documentBuilder.doneFast();
// object will be too large, assert. the extra 1KB is for headers
uassert(16389,
str::stream() << "aggregation result exceeds maximum document size ("
<< BSONObjMaxUserSize / (1024 * 1024) << "MB)",
resultArray.len() < BSONObjMaxUserSize - 1024);
}
resultArray.done();
result.appendArray("result", resultArray.arr());
}
return true;
}
示例3: listFiles
BSONObj listFiles(const BSONObj& _args, void* data) {
BSONObj cd = BSON( "0" << "." );
BSONObj args = _args.isEmpty() ? cd : _args;
uassert( 10257 , "need to specify 1 argument to listFiles" , args.nFields() == 1 );
BSONArrayBuilder lst;
string rootname = args.firstElement().valuestrsafe();
boost::filesystem::path root( rootname );
stringstream ss;
ss << "listFiles: no such directory: " << rootname;
string msg = ss.str();
uassert( 12581, msg.c_str(), boost::filesystem::exists( root ) );
boost::filesystem::directory_iterator end;
boost::filesystem::directory_iterator i( root);
while ( i != end ) {
boost::filesystem::path p = *i;
BSONObjBuilder b;
#if BOOST_VERSION >= 104400
b << "name" << p.generic_string();
#else
b << "name" << p.string();
#endif
b.appendBool( "isDirectory", is_directory( p ) );
if ( ! boost::filesystem::is_directory( p ) ) {
try {
b.append( "size" , (double)boost::filesystem::file_size( p ) );
}
catch ( ... ) {
i++;
continue;
}
}
lst.append( b.obj() );
i++;
}
BSONObjBuilder ret;
ret.appendArray( "", lst.done() );
return ret.obj();
}
示例4:
bo ReplSetConfig::MemberCfg::asBson() const {
bob b;
b << "_id" << _id;
b.append("host", h.toString());
if( votes != 1 ) b << "votes" << votes;
if( priority != 1.0 ) b << "priority" << priority;
if( arbiterOnly ) b << "arbiterOnly" << true;
if( slaveDelay ) b << "slaveDelay" << slaveDelay;
if( hidden ) b << "hidden" << hidden;
if( !buildIndexes ) b << "buildIndexes" << buildIndexes;
if( !tags.empty() ) {
BSONArrayBuilder a;
for( set<string>::const_iterator i = tags.begin(); i != tags.end(); i++ )
a.append(*i);
b.appendArray("tags", a.done());
}
return b.obj();
}
示例5: updateUpstream
bool SyncSourceFeedback::updateUpstream() {
if (theReplSet->isPrimary()) {
// primary has no one to update to
return true;
}
BSONObjBuilder cmd;
cmd.append("replSetUpdatePosition", 1);
// create an array containing objects each member connected to us and for ourself
BSONArrayBuilder array (cmd.subarrayStart("optimes"));
OID myID = _me["_id"].OID();
{
for (map<mongo::OID, OpTime>::const_iterator itr = _slaveMap.begin();
itr != _slaveMap.end(); ++itr) {
BSONObjBuilder entry(array.subobjStart());
entry.append("_id", itr->first);
entry.append("optime", itr->second);
if (itr->first == myID) {
entry.append("config", theReplSet->myConfig().asBson());
}
else {
entry.append("config", _members[itr->first]->config().asBson());
}
entry.doneFast();
}
}
array.done();
BSONObj res;
bool ok;
try {
ok = _connection->runCommand("admin", cmd.obj(), res);
}
catch (const DBException& e) {
log() << "SyncSourceFeedback error sending update: " << e.what() << endl;
resetConnection();
return false;
}
if (!ok) {
log() << "SyncSourceFeedback error sending update, response: " << res.toString() <<endl;
resetConnection();
return false;
}
return true;
}
示例6: run
void Pipeline::run(BSONObjBuilder& result) {
// We should not get here in the explain case.
verify(!pCtx->isExplain);
// the array in which the aggregation results reside
// cant use subArrayStart() due to error handling
BSONArrayBuilder resultArray;
while (auto next = getNext()) {
// Add the document to the result set.
BSONObjBuilder documentBuilder(resultArray.subobjStart());
next->toBson(&documentBuilder);
documentBuilder.doneFast();
// Object will be too large, assert. The extra 1KB is for headers.
uassert(16389,
str::stream() << "aggregation result exceeds maximum document size ("
<< BSONObjMaxUserSize / (1024 * 1024)
<< "MB)",
resultArray.len() < BSONObjMaxUserSize - 1024);
}
resultArray.done();
result.appendArray("result", resultArray.arr());
}
示例7: run
void Pipeline::run(BSONObjBuilder& result) {
/*
Iterate through the resulting documents, and add them to the result.
We do this even if we're doing an explain, in order to capture
the document counts and other stats. However, we don't capture
the result documents for explain.
*/
if (explain) {
if (!pCtx->getInRouter())
writeExplainShard(result);
else {
writeExplainMongos(result);
}
}
else {
// the array in which the aggregation results reside
// cant use subArrayStart() due to error handling
BSONArrayBuilder resultArray;
DocumentSource* finalSource = sources.back().get();
for (bool hasDoc = !finalSource->eof(); hasDoc; hasDoc = finalSource->advance()) {
Document pDocument(finalSource->getCurrent());
/* add the document to the result set */
BSONObjBuilder documentBuilder (resultArray.subobjStart());
pDocument->toBson(&documentBuilder);
documentBuilder.doneFast();
// object will be too large, assert. the extra 1KB is for headers
uassert(16389,
str::stream() << "aggregation result exceeds maximum document size ("
<< BSONObjMaxUserSize / (1024 * 1024) << "MB)",
resultArray.len() < BSONObjMaxUserSize - 1024);
}
resultArray.done();
result.appendArray("result", resultArray.arr());
}
}