in python, pymongo provides nice support mongodb geospatial index. however, c++ when use mongocxx in c++, little bit confused grammar.
for example, in python (pymongo) used
cursor = db.colection.find( { "loc": { "$near": [lon, lat] } } ).limit(10)
to nearest 10 items given location. how can same thing in c++?
i tried:
mongocxx::cursor cursor = coll.find(document{} << "loc" << open_document << "$near" << [lon, lat] << close_document << finalize);
i not sure if correct approach, , failed set number of results.
could give me instructions on geospatial index in c++? documents/examples highly apreciated.
thank much.
you can use mongocxx::options::find::limit
. check mongocxx::collection::find
. following should work :
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);
Comments
Post a Comment