In python, pymongo provides nice support for MongoDB GeoSpatial index. However, for C++ when I use mongocxx in C++, I am a little bit confused about the grammar.
For example, in python (pymongo) I used
cursor = db.colection.find(
{
"loc": {
"$near": [lon, lat]
}
}
).limit(10)
to get nearest 10 items for given location. But how can I do the same thing in C++?
I tried:
mongocxx::cursor cursor = coll.find(document{} << "loc" << open_document <<
"$near" << [lon, lat]
<< close_document << finalize);
I am not sure if this is correct approach, and I failed to set the number of results.
Could anyone give me some instructions on GeoSpatial index in C++? Documents/examples will be highly apreciated.
Thank you very much.