I have source and destination fields in my mongodb collection named Flight. Both the fields are geospatially indexed and written in lat-long format. I am using mongomapper to query it from rails controller.
I want to write a query like following.
Result= Flight.where(:source => {'$near' => location_src} , :destination => {'$near' => location_dest} )
where location_src and location_dest are gui inputs in lat-long format.
However, when I try to access the Result by writing Result.first or Result.all, it says that
Mongo::OperationFailure: can't have 2 special fields .
Can anyone suggest me what could be the workaround?
Kind Regards,
Amrish.
I found a simple workaround which serves my purpose and might be helpful to someone facing the similar scenario.
Though mongodb does not support geospatial query on multiple fields simultaneously, it still supports geospatial indexing on multiple fields simultaneously. So, we would run query on both the fields one after another as follows.
Following is the example code.
Also, one will need to set ‘$maxDistance’ => “value” according to one’s requirement.