I have a very large database (~ 6 million rows) which was imported from a csv file. I was looking at MongoDB and their documentation on GeoSpatial indexing. You need the latitude and longitude fields embedded into an array. Unfortunately, the structure I have imported has the fields seperate.
"latitude" : 54.770233, "longitude" : -6.537741,
Is there any possible way of querying the DB to calculate the twenty nearest documents within a 25 miles radius using the latitude point of 54 and longitude of -6.
I created the query in MySQL fine :
SELECT * , ( 3959 * ACOS( COS( RADIANS( 54 ) ) * COS( RADIANS( latitude
) ) * COS( RADIANS( longitude
) - RADIANS( -6 ) ) + SIN( RADIANS( 54 ) ) * SIN( RADIANS( latitude
) ) ) ) AS distance
FROM table_name
HAVING distance <25
ORDER BY distance
LIMIT 0 , 20
However, I am unsure of how to do this in Mongo without the embedded fields.
Any help would be much appreciated.