在python中,pymongo为MongoDB GeoSpatial索引提供了很好的支持。然而,对于C++,当我在C++中使用mongocxx时,我对语法有点困惑。
例如,在python (pymongo)中我使用了
cursor = db.colection.find(
{
"loc": {
"$near": [lon, lat]
}
}
).limit(10)若要获得给定位置的最接近的10个项目,请执行以下操作。但是我如何在C++中做同样的事情呢?
我试过:
mongocxx::cursor cursor = coll.find(document{} << "loc" << open_document <<
"$near" << [lon, lat]
<< close_document << finalize);我不知道这是否正确,我没有设定结果的数目。
有人能给我一些关于GeoSpatial C++索引的说明吗?文件/例子将得到高度重视。
非常感谢。
发布于 2017-04-06 00:37:50
您可以使用mongocxx::options::find::limit。也检查一下mongocxx::collection::find。下列措施应能发挥作用:
mongocxx::options::find opts;
opts.limit(10);
mongocxx::cursor cursor = coll.find(document{} << "loc" << open_document
<< "$near" << bsoncxx::builder::stream::open_array
<< lon << lat << bsoncxx::builder::stream::close_array
<< close_document << finalize, opts);https://stackoverflow.com/questions/43243200
复制相似问题