当前位置: 首页>>代码示例>>C++>>正文


C++ DBClientConnection::query方法代码示例

本文整理汇总了C++中DBClientConnection::query方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientConnection::query方法的具体用法?C++ DBClientConnection::query怎么用?C++ DBClientConnection::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBClientConnection的用法示例。


在下文中一共展示了DBClientConnection::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getCollFields

//  finds the names of the document with the most fields in a collection 
std::set<string> getCollFields(DBClientConnection& c, string db, string collection){
   
    int longest;
    
    // mongo fieldnames = sql column names
    set<string> fieldnames;
    
    // get the list of ODBC supported fields (columns) from collection.meta collection
    // collection.meta should only contain one document
    std::auto_ptr<mongo::DBClientCursor> cursor = c.query(db+"."+collection+".meta");
    
    BSONObj d = cursor->next();
    
    if (d.nFields() != 0){
        longest = d.nFields();
        d.getFieldNames(fieldnames);
    }
    
    // if no meta collection find collection with most fields
    if (longest == 0) {
    
        cursor = c.query(db+"."+collection);
    
        while( cursor->more() ) {
            //  get next doc/row/tuple
            BSONObj doc = cursor->next();
            if(longest < doc.nFields()){
                longest = doc.nFields();
                doc.getFieldNames(fieldnames);
            }
        }
    }
    return fieldnames;
}
开发者ID:DigitalParaw,项目名称:sp13_10g,代码行数:35,代码来源:mongoActions.cpp

示例2: run

void run()
{
    DBClientConnection c;
    c.connect("localhost");
    cout << "connected" << endl;

    //insert
    BSONObj p = BSON( "name" << "ken" << "age" << 20 );

    c.insert("test.persons", p);

    //query
    cout << "count: " << c.count("test.persons") << endl;

    {
        auto_ptr<DBClientCursor> cursor =
            c.query("test.persons", {});
        while(cursor->more())
            cout << cursor->next().toString() << endl;
    }

    {
        auto_ptr<DBClientCursor> cursor =
            c.query("test.persons", QUERY("age" << 20));
        while(cursor->more())
            cout << cursor->next().toString() << endl;
    }
}
开发者ID:upwell,项目名称:study,代码行数:28,代码来源:insert.cpp

示例3: updateDoc

void FXtoBSON::updateDoc(const char &t, DBClientConnection &c){
  switch(t){
  case 'd':
    {
      BSONObj findHour = find(time0, 'h');
      BSONObj findDay = find(time0, 'd');
      auto_ptr<DBClientCursor> curH = c.query(dbH, findHour, 0, 0, &projId);
      if(curH->more()){
	c.update(dbD, findDay,
		 BSON("$setOnInsert" << emptyDoc('d')), true);
	c.update(dbD, findDay,
		 BSON("$set" << 
		      BSON(to_string(time0.tm_hour) 
			   << curH->next().getField("_id"))));
      } 
    }
    break;
  case 'm':
    {
      BSONObj findDay = find(time0, 'd');
      BSONObj findMonth = find(time0, 'm');
      auto_ptr<DBClientCursor> curD = c.query(dbD, findDay, 0, 0, &projId);
      if(curD->more()){
	c.update(dbM, findMonth,
		 BSON("$setOnInsert" << emptyDoc('m')), true);
	c.update(dbM, findMonth,
		 BSON("$set" <<
		      BSON(to_string(time0.tm_mday)
			   << curD->next().getField("_id"))));
      }
    }
    break;
  case 'y':
    {
      BSONObj findMonth = find(time0, 'm');
      BSONObj findYear = find(time0, 'y');
      auto_ptr<DBClientCursor> curM = c.query(dbM, findMonth,
					      0, 0, &projId);
      if(curM->more()){
	c.update(dbY, findYear,
		 BSON("$setOnInsert" << emptyDoc('y')), true);
	c.update(dbY, findYear,
		 BSON("$set" << 
		      BSON(to_string(time0.tm_mon) <<
			   curM->next().getField("_id"))));
      }
    }
    break;
  } // switch end
}
开发者ID:anfego22,项目名称:FXdata-to-MongoDB,代码行数:50,代码来源:BSONfx.cpp

示例4: dprintf

void
plumage::stats::processMachineStats(ODSMongodbOps* ops, Date_t& ts) {
    dprintf(D_FULLDEBUG, "ODSCollectorPlugin::processMachineStats() called...\n");
    DBClientConnection* conn =  ops->m_db_conn;
    conn->ensureIndex(DB_RAW_ADS, BSON( ATTR_MY_TYPE << 1 ));
    auto_ptr<DBClientCursor> cursor = conn->query(DB_RAW_ADS, QUERY( ATTR_MY_TYPE << "Machine" ) );
    conn->ensureIndex(DB_STATS_SAMPLES_MACH, BSON( "ts" << -1 ));
    conn->ensureIndex(DB_STATS_SAMPLES_MACH, BSON( "m" << 1 ));
    conn->ensureIndex(DB_STATS_SAMPLES_MACH, BSON( "n" << 1 ));
    while( cursor->more() ) {
        BSONObj p = cursor->next();
        // write record to machine samples
        BSONObjBuilder bob;
        DATE(ts,ts);
        STRING(m,ATTR_MACHINE);
        STRING(n,ATTR_NAME);
        STRING(ar,ATTR_ARCH);
        STRING(os,ATTR_OPSYS);
        STRING(req,ATTR_REQUIREMENTS);
        INTEGER(ki,ATTR_KEYBOARD_IDLE);
        DOUBLE(la,ATTR_LOAD_AVG);
        STRING(st,ATTR_STATE);
        INTEGER(cpu,ATTR_CPUS);
        INTEGER(mem,ATTR_MEMORY);
        // TODO: these might be moved to another collection
//         STRING(gjid,ATTR_GLOBAL_JOB_ID);
//         STRING(ru,ATTR_REMOTE_USER);
//         STRING(ag,ATTR_ACCOUNTING_GROUP);
        conn->insert(DB_STATS_SAMPLES_MACH,bob.obj());
    }
}
开发者ID:AlainRoy,项目名称:htcondor,代码行数:31,代码来源:ODSStatsProcessors.cpp

示例5: run

void run() {
    DBClientConnection c;
    c.connect("localhost"); //"192.168.58.1");
    cout << "connected ok" << endl;
    BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
    c.insert("tutorial.persons", p);
    p = BSON( "name" << "Jane" << "age" << 40 );
    c.insert("tutorial.persons", p);
    p = BSON( "name" << "Abe" << "age" << 33 );
    c.insert("tutorial.persons", p);
    p = BSON( "name" << "Samantha" << "age" << 21 << "city" << "Los Angeles" << "state" << "CA" );
    c.insert("tutorial.persons", p);

    c.ensureIndex("tutorial.persons", fromjson("{age:1}"));

    cout << "count:" << c.count("tutorial.persons") << endl;

    auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", BSONObj());
    while( cursor->more() ) {
        cout << cursor->next().toString() << endl;
    }

    cout << "\nprintifage:\n";
    printIfAge(c, 33);
}
开发者ID:BendustiK,项目名称:mongo,代码行数:25,代码来源:tutorial.cpp

示例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.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 ) );
}
开发者ID:agiamas,项目名称:mongo,代码行数:32,代码来源:second.cpp

示例7: printIfAge

void printIfAge(DBClientConnection& c, int age) {
    auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") );
    while( cursor->more() ) {
        BSONObj p = cursor->next();
        cout << p.getStringField("name") << endl;
    }
}
开发者ID:BendustiK,项目名称:mongo,代码行数:7,代码来源:tutorial.cpp

示例8: queryincrement

void em_mongodb::queryincrement(std::string dbcoll,BSONElement last)
{
//	int ret = MDB_FAIL_QUERY;
	DBClientConnection* pconn = getConn();
	if(!pconn)
		return ;
	mongo::Query cond = mongo::Query().sort("$natural");
//	BSONElement last;// = minKey.firstElement();
	while(1)
	{
		std::auto_ptr<mongo::DBClientCursor> cursor = 
			pconn->query(dbcoll,cond,0,0,0,QueryOption_CursorTailable|QueryOption_AwaitData);
		while(1)
		{
			if(!cursor->more())
			{
				if(cursor->isDead())
				{
					break;
				}
				continue;
			}
			BSONObj obj = cursor->next();
			last = obj["_id"];
			//do something here...
			incrementfunc(obj);
		}
//		cond = mongo::Query("_id"<<BSON("$gt"<<last)).sort("$natural");			
	}
	boost::mutex::scoped_lock(m_iomux);
	m_connpool[pconn] = false;
	sem_post(&m_jobsem);
}	
开发者ID:7zkeeper,项目名称:emcds,代码行数:33,代码来源:em_mongodb.cpp

示例9: mongoSelect

std::auto_ptr<mongo::DBClientCursor> mongoSelect(DBClientConnection& c, string db, string collection, string fields,  BSONObj whereCond){
    
    //    
    cout << "Hello mongoSelect" << endl;
    
    std::auto_ptr<mongo::DBClientCursor> cursor = c.query(db+"."+collection, whereCond);
    return cursor;
    
}
开发者ID:DigitalParaw,项目名称:sp13_10g,代码行数:9,代码来源:mongoActions.cpp

示例10: 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 );
}
开发者ID:10genReviews,项目名称:mongo,代码行数:44,代码来源:whereExample.cpp

示例11: dumpCollection

void dumpCollection(Parameters& params) {
	DBClientConnection c;
	string hostPort(params.getHost());
	if (hostPort.find(':') == string::npos) {
		hostPort += ":";
		hostPort += to_string(params.getPort());
	}
	c.connect(hostPort);
	time_t t;
	time(&t);

	int documentCount = c.count(params.getDbCollection());

	if (params.isDebug()) {
		cout << "{ " << params.getDbCollection() << ".count: "
			<< documentCount << " }\n";
	}

	string docPrefixString(params.getDbCollection());
//	docIndex += "{";
//	docIndex += to_string(i++);
//	docIndex += "}";

	unique_ptr<DBClientCursor> cursor = c.query(params.getDbCollection(), BSONObj());

	unique_ptr<IBSONRenderer> renderer;
	switch (params.getStyle()) {
	case STYLE_DOTTED:
		renderer = unique_ptr<IBSONRenderer>(new BSONDotNotationDump(params, docPrefixString));
		break;
	case STYLE_TREE:
		renderer = unique_ptr<IBSONRenderer>(new BSONObjectTypeDump(params, docPrefixString));
		break;
	case STYLE_JSON:
	case STYLE_JSONPACKED:
		renderer = unique_ptr<IBSONRenderer>(new JSONDump(params, "  "));
		break;
	default:
		throw std::logic_error("ISE: Undefined STYLE!");
		break;
	}
	if (renderer) {
		renderer->setOutputStream(cout);
		renderer->begin(NULL);
		int documentIndex = 0;
		while (cursor->more()) {
			const BSONObj& o = cursor->next(); // Get the BSON Object
			renderer->render(o, documentIndex++, documentCount);
		}
		renderer->end(NULL);
	} else {
		throw std::logic_error("ISE: Undefined renderer!");
	}
}
开发者ID:krystalmonolith,项目名称:MongoType,代码行数:54,代码来源:mongotype.cpp

示例12: addMinToDB

void FXtoBSON::addMinToDB(const BSONObj & document,
			  DBClientConnection & c){
  BSONObj FINDhour = find(time1, 'h');
  auto_ptr<DBClientCursor> cursor = c.query(dbH, FINDhour);
  if(cursor->more()){
    c.update(dbH , FINDhour, BSON("$set" << document));
  } else {
    c.update(dbH, FINDhour,
	     BSON("$set" << emptyDoc('h')), true);
    c.update(dbH, FINDhour, BSON("$set" << document));
  }
}
开发者ID:anfego22,项目名称:FXdata-to-MongoDB,代码行数:12,代码来源:BSONfx.cpp

示例13: outputToFile

void outputToFile(DBClientConnection& c){
	ofstream signal;
	ofstream noise;
	signal.open("signal.txt");
	noise.open("noise.txt");

	auto_ptr<DBClientCursor> noiseCursor =c.query("hw3.noise", Query());
	auto_ptr<DBClientCursor> signalCursor =c.query("hw3.signal", Query());
	//output to file
	while (noiseCursor->more()){
		BSONObj single = noiseCursor->next();
		noise<<single.getStringField("date")<<","<<single.getField("value").Double()
				<<","<<single.getField("volume").Int()<<'\n';
	}
	while (signalCursor->more()){
		BSONObj single = signalCursor->next();
		signal<<single.getStringField("date")<<","<<single.getField("value").Double()
				<<","<<single.getField("volume").Int()<<'\n';
	}

}
开发者ID:jpalonso1,项目名称:BigData,代码行数:21,代码来源:mainhw3.cpp

示例14: 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);
		}
	}
}
开发者ID:jpalonso1,项目名称:BigData,代码行数:30,代码来源:mainhw3.cpp

示例15: printIfAge

int printIfAge(DBClientConnection& c, int age) {
    std::auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") );
    if (!cursor.get()) {
        cout << "query failure" << endl;
        return EXIT_FAILURE;
    }

    while( cursor->more() ) {
        BSONObj p = cursor->next();
        cout << p.getStringField("name") << endl;
    }
    return EXIT_SUCCESS;
}
开发者ID:504com,项目名称:mongo,代码行数:13,代码来源:tutorial.cpp


注:本文中的DBClientConnection::query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。