本文整理汇总了C++中DBClientReplicaSet::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientReplicaSet::insert方法的具体用法?C++ DBClientReplicaSet::insert怎么用?C++ DBClientReplicaSet::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBClientReplicaSet
的用法示例。
在下文中一共展示了DBClientReplicaSet::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc , const char ** argv ) {
unsigned nThreads = 1;
bool print = false;
bool testTimeout = false;
for ( int i=1; i<argc; i++ ) {
if ( mongoutils::str::equals( "--threads" , argv[i] ) ) {
nThreads = atoi( argv[++i] );
}
else if ( mongoutils::str::equals( "--print" , argv[i] ) ) {
print = true;
}
// Run a special mode to demonstrate the DBClientReplicaSet so_timeout option.
else if ( mongoutils::str::equals( "--testTimeout" , argv[i] ) ) {
testTimeout = true;
}
else {
cerr << "unknown option: " << argv[i] << endl;
return EXIT_FAILURE;
}
}
Status status = client::initialize();
if ( !status.isOK() ) {
std::cout << "failed to initialize the client driver: " << status.toString() << endl;
return EXIT_FAILURE;
}
string errmsg;
ConnectionString cs = ConnectionString::parse( "foo/127.0.0.1" , errmsg );
if ( ! cs.isValid() ) {
cout << "error parsing url: " << errmsg << endl;
return EXIT_FAILURE;
}
DBClientReplicaSet * conn = static_cast<DBClientReplicaSet*>( cs.connect( errmsg, testTimeout ? 10 : 0 ) );
if ( ! conn ) {
cout << "error connecting: " << errmsg << endl;
return EXIT_FAILURE;
}
string collName = "test.rs1";
conn->dropCollection( collName );
if ( testTimeout ) {
conn->insert( collName, BSONObj() );
try {
conn->count( collName, BSON( "$where" << "sleep(40000)" ) );
} catch( DBException& ) {
return EXIT_SUCCESS;
}
cout << "expected socket exception" << endl;
return EXIT_FAILURE;
}
vector<boost::shared_ptr<boost::thread> > threads;
for ( unsigned i=0; i<nThreads; i++ ) {
string errmsg;
threads.push_back( boost::shared_ptr<boost::thread>(
new boost::thread(
boost::bind( workerThread ,
collName ,
print ,
static_cast<DBClientReplicaSet*>( cs.connect(errmsg) ) ) ) ) );
}
for ( unsigned i=0; i<threads.size(); i++ ) {
threads[i]->join();
}
return EXIT_SUCCESS;
}