I\'m starting to use mongoDb and I\'m stuck with a simple use case.
Let\'s say I\'ve got a collection \'aCollection\' with entries such as this:
It looks like MongoDB 3.2 provides fairly simple and elegant way to create GeoJSON points using aggregation framework.
We had to perform the transformation on approximately 2 Million records two times a day, so aggregation framework was the fastest and probably most reliable approach.
Below is a Mongoose example of how to transform geolocation data from collection with longitude/latitude into a collection with GeoJSON points.
Locations
.aggregate([
{
$project : {
_id: 0,
"location": {
"type": { $literal: "Point" },
"coordinates": ["$longitude", "$latitude"]
}
}
},
{
$out : 'test_1'
}])
.exec(function(err,data) {
if (err) {
console.error(err);
} else {
console.log("Done transforming.");
}
});