I have a collection in mongodb that stores information about airports and I need to perform some Geospatial Queries.
One example document from this collection looks like this:
{ "_id" : ObjectId("528e8134556062edda12ffe6"), "id" : 6523, "ident" : "00A", "type" : "heliport", "name" : "Total Rf Heliport", "latitude_deg" : 40.07080078125, "longitude_deg" : -74.9336013793945, "elevation_ft" : 11, ... }
I want to transform all documents in the collection to have a structure like this:
{ "_id": ObjectId("528e8134556062edda12ffe6"), "id" : 6523, "ident" : "00A", "type" : "heliport", "name" : "Total Rf Heliport", "longitude_deg" : 17.27, "latitude_deg" : 52.22, "loc" : { "type" : "Point", "coordinates" : [ 17.27, 52.22 ] }, ... }
The provided javascript code should achieve this transformation:
var cursor = db.airports.find() cursor.forEach(function(input) { x = input.latitude_deg; y = input.longitude_deg; id = input._id; db.airports.update({"_id":id},{$set:{"loc":{"type":"Point","coordinates":[y,x]}}}); });
However, I am struggling to create a Java program that accomplishes the same task. If anyone can provide guidance on how to solve this problem, it would be greatly appreciated.
Thank you in advance for your help and apologies for any language barriers!