MongoDB c++驱动查询错误
MongoDB C++ driver query error
MongoDB c++驱动程序正在做我的头。我有一个工作驱动程序,它可以很好地用于所有查询,除了下面的查询,它会停止程序编译。
代码应该根据MongoDB文档工作:http://docs.mongodb.org/ecosystem/drivers/cpp-to-sql-to-mongo-shell/
目的是只选择集合中所有文档的"name"字段。
using namespace std;
using namespace mongo;
DBClientConnection c;
c.connect("localhost");
auto_ptr<DBClientCursor> cursor = c.query("db.coll", Query(), 0, 0, BSON("name" << 1));
//auto_ptr<DBClientCursor> cursor = c.query("db.coll", Query().sort("_id", -1), 0, 0);
//auto_ptr<DBClientCursor> cursor = c.query("db.coll", Query());
//auto_ptr<DBClientCursor> cursor = c.query("db.coll", QUERY("type" << "blog"));
但是,我得到以下错误:
error: no matching function for call to ‘mongo::DBClientConnection::query(const char [19], mongo::Query, int, int, mongo::BSONObj)’
mongodriver/include/mongo/client/dbclientinterface.h:1274: note: candidates are: virtual std::auto_ptr<mongo::DBClientCursor> mongo::DBClientConnection::query(const std::string&, mongo::Query, int, int, const mongo::BSONObj*, int, int)
我已经尝试了我能想到的所有方法来使调用参数与建议的候选参数匹配,但只成功地生成了不同的错误。注意,注释掉的查询都可以正常工作。令人沮丧。
提前感谢你的真知灼见
@mjhall,
我相信你指出上述查询不起作用是正确的。当示例传递一个BSONObj时,c.query()期望一个BSONObj*。你能试着跟着做,看看是否对你有用吗?
DBClientConnection c;
c.connect("localhost");
BSONObj b = BSON("name" << 1);
auto_ptr<DBClientCursor> cursor = c.query("db.coll", Query(), 0, 0, &b);
相关文章:
- 仅在Android上查询时SQL逻辑错误
- glGenQuery总是返回非查询对象,glBeginQuery返回错误
- Mysql 查询错误
- C sqlite3插入或替换查询我认为是错误的
- VC++使用gumbo查询时出现问题(链接错误)
- MongoDB C++ 驱动程序 -- 通过引用传递查询对象在随后使用其排序时会引发错误
- C++程序中存在SQL查询语法错误,但可在MySQL工作台中使用
- 查询从内存映射文件检索到的Rtree时出现分段错误
- 使用 C++ 旧驱动程序的 mongodb 查询会导致 BSONElement:错误类型 -64
- C++类查询错误:" "左侧必须指向类/结构/联合
- JSON子对象的C++查询错误
- MySQL C API:从不同线程运行查询时出现分段错误
- c++程序退出段错误,查询时与MySQL服务器失去连接
- PostgreSql查询参数数据类型错误
- 体式 API 查询错误"Empty Field Name"
- 在尝试维基百科查询时,CURLPP 400错误请求
- MongoDB c++驱动查询错误
- DeviceIoControl for SCSI查询命令返回错误50
- SQL Server Compact Edition 3.5 为简单查询提供"Multiple-step operation generated errors"错误
- 查询的类成员返回错误的值