我有一个mongodb replica-set存储计算状态数据,如cpu,内存等。 在我的Web服务器中,我使用mongodb c ++驱动程序来查询来自mongodb的数据。当结果文档超过330,000时,mongodb驱动程序报告字段未找到异常:
2015-01-22T16:57:59.848+0800 Assertion: 13111:field not found, expected type 7
但是如果我们减少返回的数字,它就能正常工作。以下是我的代码:
shared_ptr<Datas> DataService::QueryByEpochMin(string const& type, uint64_t start_time, uint64_t end_time) {
Configuration& config = MyApp::Instance().config();
shared_ptr<MongoSession> session = MongoSessionFactory::GetSession();
shared_ptr<Datas> datas(new Datas());
BSONObjBuilder condition;
BSONObjBuilder t1;
t1.append("$gte", static_cast<long long>(start_time));
BSONObjBuilder t2;
t2.append("$lt", static_cast<long long>(end_time));
condition.append("epoch_min", t1.obj());
condition.append("epoch_min", t2.obj());
BSONObjBuilder sortBuilder;
sortBuilder.append("epoch_min", 1);
Query query(condition.obj());
Query queryWithSort(query.sort(sortBuilder.obj()));
std::unique_ptr<DBClientCursor> cursor = session->get().query(config.mongo_db_name + "." + type + "_data", queryWithSort, 330000);
while (cursor->more()) {
shared_ptr<Data> data(new Data());
BSONObj record = cursor->next();
data->host_id = record.getField("host_id").OID();
data->epoch = record.getField("epoch").numberLong();
data->epoch_min = record.getField("epoch_min").numberLong();
data->load = static_cast<float>(record.getField("load").Double());
datas->Add(data);
}
return datas;
}
在mongodb c++ driver doc中,如果我没有指定DBClientBase :: query函数的nToReturn参数,则它是无限制的。那导致这个问题的原因是什么?