在 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);
我不确定这是否是正确的方法,并且我未能设置结果数。
谁能给我一些关于 C++ 中地理空间索引的说明?文档/示例将受到高度赞赏。
非常感谢。