本文整理汇总了C++中DBClientConnection::dropCollection方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientConnection::dropCollection方法的具体用法?C++ DBClientConnection::dropCollection怎么用?C++ DBClientConnection::dropCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBClientConnection
的用法示例。
在下文中一共展示了DBClientConnection::dropCollection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupDatabase
/* ****************************************************************************
*
* setupDatabase -
*
* This function (which is called before every test) cleans the database
*/
void setupDatabase(void) {
mongoConnect("localhost");
DBClientConnection* connection = getMongoConnection();
connection->dropCollection(REGISTRATIONS_COLL);
connection->dropCollection(ENTITIES_COLL);
connection->dropCollection(SUBSCRIBECONTEXT_COLL);
connection->dropCollection(SUBSCRIBECONTEXTAVAIL_COLL);
connection->dropCollection(ASSOCIATIONS_COLL);
setRegistrationsCollectionName(REGISTRATIONS_COLL);
setEntitiesCollectionName(ENTITIES_COLL);
setSubscribeContextCollectionName(SUBSCRIBECONTEXT_COLL);
setSubscribeContextAvailabilityCollectionName(SUBSCRIBECONTEXTAVAIL_COLL);
setAssociationsCollectionName(ASSOCIATIONS_COLL);
}
示例2: main
int main( int argc, const char **argv ) {
const char *port = "27017";
if ( argc != 1 ) {
if ( argc != 3 )
throw -12;
port = argv[ 2 ];
}
DBClientConnection conn;
string errmsg;
if ( ! conn.connect( string( "127.0.0.1:" ) + port , errmsg ) ) {
cout << "couldn't connect : " << errmsg << endl;
throw -11;
}
const char * ns = "test.test1";
conn.dropCollection(ns);
// clean up old data from any previous tests
conn.remove( ns, BSONObj() );
assert( conn.findOne( ns , BSONObj() ).isEmpty() );
// test insert
conn.insert( ns ,BSON( "name" << "eliot" << "num" << 1 ) );
assert( ! conn.findOne( ns , BSONObj() ).isEmpty() );
// test remove
conn.remove( ns, BSONObj() );
assert( conn.findOne( ns , BSONObj() ).isEmpty() );
// insert, findOne testing
conn.insert( ns , BSON( "name" << "eliot" << "num" << 1 ) );
{
BSONObj res = conn.findOne( ns , BSONObj() );
assert( strstr( res.getStringField( "name" ) , "eliot" ) );
assert( ! strstr( res.getStringField( "name2" ) , "eliot" ) );
assert( 1 == res.getIntField( "num" ) );
}
// cursor
conn.insert( ns ,BSON( "name" << "sara" << "num" << 2 ) );
{
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObj() );
int count = 0;
while ( cursor->more() ) {
count++;
BSONObj obj = cursor->next();
}
assert( count == 2 );
}
{
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSON( "num" << 1 ) );
int count = 0;
while ( cursor->more() ) {
count++;
BSONObj obj = cursor->next();
}
assert( count == 1 );
}
{
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSON( "num" << 3 ) );
int count = 0;
while ( cursor->more() ) {
count++;
BSONObj obj = cursor->next();
}
assert( count == 0 );
}
// update
{
BSONObj res = conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() );
assert( ! strstr( res.getStringField( "name2" ) , "eliot" ) );
BSONObj after = BSONObjBuilder().appendElements( res ).append( "name2" , "h" ).obj();
conn.update( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() , after );
res = conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() );
assert( ! strstr( res.getStringField( "name2" ) , "eliot" ) );
assert( conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() ).isEmpty() );
conn.update( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() , after );
res = conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() );
assert( strstr( res.getStringField( "name" ) , "eliot" ) );
assert( strstr( res.getStringField( "name2" ) , "h" ) );
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
//.........这里部分代码省略.........
示例3: main
int main( int argc, const char **argv ) {
const char *port = "27017";
if ( argc != 1 ) {
if ( argc != 3 ) {
std::cout << "need to pass port as second param" << endl;
return EXIT_FAILURE;
}
port = argv[ 2 ];
}
DBClientConnection conn;
string errmsg;
if ( ! conn.connect( string( "127.0.0.1:" ) + port , errmsg ) ) {
cout << "couldn't connect : " << errmsg << endl;
return EXIT_FAILURE;
}
const char * ns = "test.test1";
conn.dropCollection(ns);
// clean up old data from any previous tests
conn.remove( ns, BSONObj() );
verify( conn.findOne( ns , BSONObj() ).isEmpty() );
// test insert
conn.insert( ns ,BSON( "name" << "eliot" << "num" << 1 ) );
verify( ! conn.findOne( ns , BSONObj() ).isEmpty() );
// test remove
conn.remove( ns, BSONObj() );
verify( conn.findOne( ns , BSONObj() ).isEmpty() );
// insert, findOne testing
conn.insert( ns , BSON( "name" << "eliot" << "num" << 1 ) );
{
BSONObj res = conn.findOne( ns , BSONObj() );
verify( strstr( res.getStringField( "name" ) , "eliot" ) );
verify( ! strstr( res.getStringField( "name2" ) , "eliot" ) );
verify( 1 == res.getIntField( "num" ) );
}
// cursor
conn.insert( ns ,BSON( "name" << "sara" << "num" << 2 ) );
{
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObj() );
int count = 0;
while ( cursor->more() ) {
count++;
BSONObj obj = cursor->next();
}
verify( count == 2 );
}
{
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSON( "num" << 1 ) );
int count = 0;
while ( cursor->more() ) {
count++;
BSONObj obj = cursor->next();
}
verify( count == 1 );
}
{
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSON( "num" << 3 ) );
int count = 0;
while ( cursor->more() ) {
count++;
BSONObj obj = cursor->next();
}
verify( count == 0 );
}
// update
{
BSONObj res = conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() );
verify( ! strstr( res.getStringField( "name2" ) , "eliot" ) );
BSONObj after = BSONObjBuilder().appendElements( res ).append( "name2" , "h" ).obj();
conn.update( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() , after );
res = conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() );
verify( ! strstr( res.getStringField( "name2" ) , "eliot" ) );
verify( conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() ).isEmpty() );
conn.update( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() , after );
res = conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() );
verify( strstr( res.getStringField( "name" ) , "eliot" ) );
verify( strstr( res.getStringField( "name2" ) , "h" ) );
verify( conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() ).isEmpty() );
// upsert
conn.update( ns , BSONObjBuilder().append( "name" , "eliot2" ).obj() , after , 1 );
verify( ! conn.findOne( ns , BSONObjBuilder().append( "name" , "eliot" ).obj() ).isEmpty() );
}
//.........这里部分代码省略.........