本文整理汇总了C++中DBClientConnection::validate方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientConnection::validate方法的具体用法?C++ DBClientConnection::validate怎么用?C++ DBClientConnection::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBClientConnection
的用法示例。
在下文中一共展示了DBClientConnection::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
assert( conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() ).isEmpty() );
// upsert
conn.update( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() , after , 1 );
assert( ! conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() ).isEmpty() );
}
{ // ensure index
assert( conn.ensureIndex( ns , BSON( "name" << 1 ) ) );
assert( ! conn.ensureIndex( ns , BSON( "name" << 1 ) ) );
}
{ // hint related tests
assert( conn.findOne(ns, "{}")["name"].str() == "sara" );
assert( conn.findOne(ns, "{ name : 'eliot' }")["name"].str() == "eliot" );
assert( conn.getLastError() == "" );
// nonexistent index test
bool asserted = false;
try {
conn.findOne(ns, Query("{name:\"eliot\"}").hint("{foo:1}"));
}
catch ( ... ){
asserted = true;
}
assert( asserted );
//existing index
assert( conn.findOne(ns, Query("{name:'eliot'}").hint("{name:1}")).hasElement("name") );
// run validate
assert( conn.validate( ns ) );
}
{ // timestamp test
const char * tsns = "test.tstest1";
conn.dropCollection( tsns );
{
mongo::BSONObjBuilder b;
b.appendTimestamp( "ts" );
conn.insert( tsns , b.obj() );
}
mongo::BSONObj out = conn.findOne( tsns , mongo::BSONObj() );
Date_t oldTime = out["ts"].timestampTime();
unsigned int oldInc = out["ts"].timestampInc();
{
mongo::BSONObjBuilder b1;
b1.append( out["_id"] );
mongo::BSONObjBuilder b2;
b2.append( out["_id"] );
b2.appendTimestamp( "ts" );
conn.update( tsns , b1.obj() , b2.obj() );
}
BSONObj found = conn.findOne( tsns , mongo::BSONObj() );
cout << "old: " << out << "\nnew: " << found << endl;
assert( ( oldTime < found["ts"].timestampTime() ) ||
( oldTime == found["ts"].timestampTime() && oldInc < found["ts"].timestampInc() ) );
示例2: main
//.........这里部分代码省略.........
b.appendTimeT("ttltime", time(0));
b.append("name", "foo");
conn.insert(ttlns, b.obj());
}
conn.ensureIndex(ttlns, BSON("ttltime" << 1), false, false, "", true, false, -1, 5);
verify(!conn.findOne(ttlns, BSONObjBuilder().append("name", "foo").obj()).isEmpty());
// Sleep 66 seconds, 60 seconds for the TTL loop, 5 seconds for the TTL and 1 to ensure
sleepsecs(66);
verify(conn.findOne(ttlns, BSONObjBuilder().append("name", "foo").obj()).isEmpty());
}
{
// hint related tests
// tokumx doesn't reorder documents just because you updated one, what even is that
verify( conn.findOne(ns, "{}")["name"].str() == "eliot" );
verify( conn.findOne(ns, "{ name : 'sara' }")["name"].str() == "sara" );
verify( conn.getLastError() == "" );
// nonexistent index test
bool asserted = false;
try {
conn.findOne(ns, Query("{name:\"eliot\"}").hint("{foo:1}"));
}
catch ( ... ) {
asserted = true;
}
verify( asserted );
//existing index
verify( conn.findOne(ns, Query("{name:'eliot'}").hint("{name:1}")).hasElement("name") );
// run validate
verify( conn.validate( ns ) );
}
{
// timestamp test
const char * tsns = "test.tstest1";
conn.dropCollection( tsns );
{
mongo::BSONObjBuilder b;
b.appendTimestamp( "ts" );
conn.insert( tsns , b.obj() );
}
mongo::BSONObj out = conn.findOne( tsns , mongo::BSONObj() );
Date_t oldTime = out["ts"].timestampTime();
unsigned int oldInc = out["ts"].timestampInc();
{
mongo::BSONObjBuilder b1;
b1.append( out["_id"] );
mongo::BSONObjBuilder b2;
b2.append( out["_id"] );
b2.appendTimestamp( "ts" );
conn.update( tsns , b1.obj() , b2.obj() );
}
BSONObj found = conn.findOne( tsns , mongo::BSONObj() );
cout << "old: " << out << "\nnew: " << found << endl;
verify( ( oldTime < found["ts"].timestampTime() ) ||