本文整理汇总了C++中DBClientConnection::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientConnection::remove方法的具体用法?C++ DBClientConnection::remove怎么用?C++ DBClientConnection::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBClientConnection
的用法示例。
在下文中一共展示了DBClientConnection::remove方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scrub
void scrub(DBClientConnection& c){
//DES: finds and moves noise documents found in the database
//IN: connection to the mongo database
auto_ptr<DBClientCursor> noiseCursor[6];
//look for negative volume
noiseCursor[0] = c.query("hw3.signal", BSON("volume"<<LTE<<0.0));
//find excessive price (>5 dollars)
noiseCursor[1] = c.query("hw3.signal", BSON("value"<<GTE<<5.0));
//find excessive negative price (<-5 dollars)
noiseCursor[2] = c.query("hw3.signal", BSON("value"<<LTE<<-5.0));
//find weekend dates
noiseCursor[3] = c.query("hw3.signal", Query("{date: /[0-9]{7}2./i }"));
//find 9 am trades
noiseCursor[4] = c.query("hw3.signal", Query("{date: /[0-9]{8}:09./i }"));
//find 5 pm trades
noiseCursor[5] = c.query("hw3.signal", Query("{date: /[0-9]{8}:17./i }"));
//loop through each noise type and move the errors from the signal collection to the
//noise collection
for (int i=0;i<6;i++){
while (noiseCursor[i]->more()){
BSONObj singleNoise = noiseCursor[i]->next();
//add to noise db
c.insert("hw3.noise", singleNoise);
//remove from signal db
c.remove("hw3.signal",singleNoise);
}
}
}
示例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.second";
conn.remove( ns , BSONObj() );
conn.insert( ns , BSON( "name" << "eliot" << "num" << 17 ) );
conn.insert( ns , BSON( "name" << "sara" << "num" << 24 ) );
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObj() );
cout << "using cursor" << endl;
while ( cursor->more() ) {
BSONObj obj = cursor->next();
cout << "\t" << obj.jsonString() << endl;
}
conn.ensureIndex( ns , BSON( "name" << 1 << "num" << -1 ) );
}
示例3: 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.where";
conn.remove( ns , BSONObj() );
conn.insert( ns , BSON( "name" << "eliot" << "num" << 17 ) );
conn.insert( ns , BSON( "name" << "sara" << "num" << 24 ) );
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObj() );
while ( cursor->more() ) {
BSONObj obj = cursor->next();
cout << "\t" << obj.jsonString() << endl;
}
cout << "now using $where" << endl;
Query q = Query("{}").where("this.name == name" , BSON( "name" << "sara" ));
cursor = conn.query( ns , q );
int num = 0;
while ( cursor->more() ) {
BSONObj obj = cursor->next();
cout << "\t" << obj.jsonString() << endl;
num++;
}
MONGO_verify( num == 1 );
}
示例4: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
client::initialize();
try {
DBClientConnection c;
c.connect("localhost");
std::cout << "connected ok" << std::endl;
c.remove("deuda.bonosletras", BSONObj());
std::cout << "reg. in deuda.bonosletras before=" << c.count("deuda.bonosletras") << std::endl;
for (int i = 0; i < 100000; ++i)
{
BSONObj p = BSONObjBuilder().append("name", "Joe").append("age", i).obj();
c.insert("deuda.bonosletras", p);
}
std::cout << "reg. in deuda.bonosletras after =" << c.count("deuda.bonosletras") << std::endl;
std::auto_ptr<DBClientCursor> cursor =
c.query("deuda.bonosletras", QUERY("age" << 100));
while (cursor->more()) {
BSONObj p = cursor->next();
std::cout << p.getStringField("name") << std::endl;
}
} catch( const DBException &e ) {
std::cout << "caught " << e.what() << std::endl;
}
return EXIT_SUCCESS;
return a.exec();
}
示例5: mongoRemove
v8::Handle<v8::Value> mongoRemove(const v8::Arguments& args){
jsassert( args.Length() == 2 , "remove needs 2 args" );
jsassert( args[1]->IsObject() , "have to remove an object template" );
DBClientConnection * conn = getConnection( args );
GETNS;
v8::Handle<v8::Object> in = args[1]->ToObject();
BSONObj o = v8ToMongo( in );
DDD( "want to remove : " << o.jsonString() );
try {
conn->remove( ns , o );
}
catch ( ... ){
return v8::ThrowException( v8::String::New( "socket error on remove" ) );
}
return v8::Undefined();
}
示例6: 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
//.........这里部分代码省略.........
示例7: main
//.........这里部分代码省略.........
for(int i = 0; i < numProcesses * numProcesses; i++){
//Point_SendTime[i] = -1;
Point_SendComm.push_back(vector<int>());
}
for(int i = 0; i < numProcesses * numProcesses; i++){
//Point_SendTime[i] = -1;
Point_SendTag.push_back(vector<int>());
}
for(int i = 0; i < numProcesses * numProcesses; i++){
//Point_SendTime[i] = -1;
Point_SendLength.push_back(vector<long long int>());
}
cout << tid_temp << endl;
char *buff;
buff = (char*) malloc (64);
sprintf(buff , "%" PRIx64, tid_temp);
TraceId = string(buff);
free(buff);
auto_ptr<DBClientCursor> cursor = DBConnection.query("Otf2Data.TraceIds", Query("{TraceId: \"" + TraceId + "\", Status: \"done\"}"));
if(cursor->more()){
cout << "Трасса с таким id уже сществует в БД" << endl;
}
else{
DBConnection.remove("Otf2Data.Events", Query("{TraceId: \"" + TraceId + "\"}"));
DBConnection.remove("Otf2Data.PointOperations", Query("{TraceId: \"" + TraceId + "\"}"));
OTF2_GlobalDefReader* global_def_reader = OTF2_Reader_GetGlobalDefReader(reader);
// creating global definition callbacks handle
OTF2_GlobalDefReaderCallbacks* global_def_callbacks = OTF2_GlobalDefReaderCallbacks_New();
// setting global definition reader callbacks to handle
// получаем все строки
OTF2_GlobalDefReaderCallbacks_SetStringCallback( global_def_callbacks, print_global_def_string );
// получаем названия регионов
OTF2_GlobalDefReaderCallbacks_SetRegionCallback( global_def_callbacks, print_global_def_region );
OTF2_GlobalDefReaderCallbacks_SetLocationCallback(global_def_callbacks, &GlobDefLocation_Register);
//OTF2_GlobalDefReaderCallbacks_SetCommCallback (global_def_callbacks, &GlobDefCommunicator_Register);
//OTF2_GlobalDefReaderCallbacks_SetGroupCallback(global_def_callbacks, &GlobDefGroup_Register);
// registering callbacks and deleting callbacks handle
OTF2_Reader_RegisterGlobalDefCallbacks(reader, global_def_reader, global_def_callbacks, reader);
OTF2_GlobalDefReaderCallbacks_Delete( global_def_callbacks );
// reading all global definitions
uint64_t definitions_read = 0;
OTF2_Reader_ReadAllGlobalDefinitions( reader, global_def_reader, &definitions_read );
printf("Definitions_read = %"PRIu64"\n", definitions_read);
示例8: 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() );
}
//.........这里部分代码省略.........
示例9: mongoUnsubscribeContext
/* ****************************************************************************
*
* mongoUnsubscribeContext -
*/
HttpStatusCode mongoUnsubscribeContext(UnsubscribeContextRequest* requestP, UnsubscribeContextResponse* responseP)
{
/* Take semaphore. The LM_S* family of macros combines semaphore release with return */
semTake();
LM_T(LmtMongo, ("Unsubscribe Context"));
DBClientConnection* connection = getMongoConnection();
/* No matter if success or failure, the subscriptionId in the response is always the one
* in the request */
responseP->subscriptionId = requestP->subscriptionId;
/* Look for document */
BSONObj sub;
try {
OID id = OID(requestP->subscriptionId.get());
LM_T(LmtMongo, ("findOne() in '%s' collection _id '%s'}", getSubscribeContextCollectionName(),
requestP->subscriptionId.get().c_str()));
sub = connection->findOne(getSubscribeContextCollectionName(), BSON("_id" << id));
if (sub.isEmpty()) {
responseP->statusCode.fill(SccContextElementNotFound, std::string("subscriptionId: '") + requestP->subscriptionId.get() + "'");
LM_SR(SccOk);
}
}
catch( const AssertionException &e ) {
/* This happens when OID format is wrong */
// FIXME: this checking should be done at parsing stage, without progressing to
// mongoBackend. By the moment we can live this here, but we should remove in the future
// (old issue #95)
responseP->statusCode.fill(SccContextElementNotFound);
LM_SR(SccOk);
}
catch( const DBException &e ) {
responseP->statusCode.fill(SccReceiverInternalError,
std::string("collection: ") + getSubscribeContextCollectionName() +
" - findOne() _id: " + requestP->subscriptionId.get() +
" - exception: " + e.what());
LM_SR(SccOk);
}
/* Remove document in MongoDB */
// FIXME: I will prefer to do the find and remove in a single operation. Is the some similar
// to findAndModify for this?
try {
LM_T(LmtMongo, ("remove() in '%s' collection _id '%s'}", getSubscribeContextCollectionName(),
requestP->subscriptionId.get().c_str()));
connection->remove(getSubscribeContextCollectionName(), BSON("_id" << OID(requestP->subscriptionId.get())));
}
catch( const DBException &e ) {
responseP->statusCode.fill(SccReceiverInternalError,
std::string("collection: ") + getSubscribeContextCollectionName() +
" - remove() _id: " + requestP->subscriptionId.get().c_str() +
" - exception: " + e.what());
LM_SR(SccOk);
}
/* Destroy any previous ONTIMEINTERVAL thread */
getNotifier()->destroyOntimeIntervalThreads(requestP->subscriptionId.get());
responseP->statusCode.fill(SccOk);
LM_SR(SccOk);
}
示例10: mongoUnsubscribeContextAvailability
/* ****************************************************************************
*
* mongoUnsubscribeContextAvailability -
*/
HttpStatusCode mongoUnsubscribeContextAvailability(UnsubscribeContextAvailabilityRequest* requestP, UnsubscribeContextAvailabilityResponse* responseP)
{
reqSemTake(__FUNCTION__, "ngsi9 unsubscribe request");
LM_T(LmtMongo, ("Unsubscribe Context Availability"));
DBClientConnection* connection = getMongoConnection();
/* No matter if success or failure, the subscriptionId in the response is always the one
* in the request */
responseP->subscriptionId = requestP->subscriptionId;
/* Look for document */
BSONObj sub;
try {
OID id = OID(requestP->subscriptionId.get());
LM_T(LmtMongo, ("findOne() in '%s' collection _id '%s'}", getSubscribeContextAvailabilityCollectionName(),
requestP->subscriptionId.get().c_str()));
mongoSemTake(__FUNCTION__, "findOne in SubscribeContextAvailabilityCollection");
sub = connection->findOne(getSubscribeContextAvailabilityCollectionName(), BSON("_id" << id));
mongoSemGive(__FUNCTION__, "findOne in SubscribeContextAvailabilityCollection");
if (sub.isEmpty()) {
responseP->statusCode.fill(SccContextElementNotFound);
reqSemGive(__FUNCTION__, "ngsi9 unsubscribe request (no subscriptions)");
return SccOk;
}
}
catch( const AssertionException &e ) {
/* This happens when OID format is wrong */
// FIXME: this checking should be done at parsing stage, without progressing to
// mongoBackend. By the moment we can live this here, but we should remove in the future
// (odl issues #95)
mongoSemGive(__FUNCTION__, "findOne in SubscribeContextAvailabilityCollection (mongo assertion exception)");
reqSemGive(__FUNCTION__, "ngsi9 unsubscribe request (mongo assertion exception)");
responseP->statusCode.fill(SccContextElementNotFound);
return SccOk;
}
catch( const DBException &e ) {
mongoSemGive(__FUNCTION__, "findOne in SubscribeContextAvailabilityCollection (mongo db exception)");
reqSemGive(__FUNCTION__, "ngsi9 unsubscribe request (mongo db exception)");
responseP->statusCode.fill(SccReceiverInternalError,
std::string("collection: ") + getSubscribeContextAvailabilityCollectionName() +
" - findOne() _id: " + requestP->subscriptionId.get() +
" - exception: " + e.what());
return SccOk;
}
catch(...) {
mongoSemGive(__FUNCTION__, "findOne in SubscribeContextAvailabilityCollection (mongo generic exception)");
reqSemGive(__FUNCTION__, "ngsi9 unsubscribe request (mongo generic exception)");
responseP->statusCode.fill(SccReceiverInternalError,
std::string("collection: ") + getSubscribeContextAvailabilityCollectionName() +
" - findOne() _id: " + requestP->subscriptionId.get() +
" - exception: " + "generic");
return SccOk;
}
/* Remove document in MongoDB */
// FIXME: I would prefer to do the find and remove in a single operation. Is the some similar
// to findAndModify for this?
try {
LM_T(LmtMongo, ("remove() in '%s' collection _id '%s'}", getSubscribeContextAvailabilityCollectionName(),
requestP->subscriptionId.get().c_str()));
mongoSemTake(__FUNCTION__, "remove in SubscribeContextAvailabilityCollection");
connection->remove(getSubscribeContextAvailabilityCollectionName(), BSON("_id" << OID(requestP->subscriptionId.get())));
mongoSemGive(__FUNCTION__, "remove in SubscribeContextAvailabilityCollection");
}
catch( const DBException &e ) {
mongoSemGive(__FUNCTION__, "remove in SubscribeContextAvailabilityCollection (mongo db exception)");
reqSemGive(__FUNCTION__, "ngsi9 unsubscribe request (mongo db exception)");
responseP->statusCode.fill(SccReceiverInternalError,
std::string("collection: ") + getSubscribeContextAvailabilityCollectionName() +
" - remove() _id: " + requestP->subscriptionId.get().c_str() +
" - exception: " + e.what());
return SccOk;
}
catch(...) {
mongoSemGive(__FUNCTION__, "remove in SubscribeContextAvailabilityCollection (mongo generic exception)");
reqSemGive(__FUNCTION__, "ngsi9 unsubscribe request (mongo generic exception)");
responseP->statusCode.fill(SccReceiverInternalError,
std::string("collection: ") + getSubscribeContextAvailabilityCollectionName() +
" - remove() _id: " + requestP->subscriptionId.get().c_str() +
" - exception: " + "generic");
return SccOk;
}
responseP->statusCode.fill(SccOk);
reqSemGive(__FUNCTION__, "ngsi9 unsubscribe request");
return SccOk;
}