Suppose a mongodb collection schema like this:
{
"_id" : ObjectId("5a5b2657a19692e18a3792ad"),
"Toponym" : "Climate station Stavenhagen",
"Lat" : 53.33333,
"Lon" : "13.99999",
"SensorMaker" : "Hitachi",
"SensorClass" : "Thermometer",
"Dimension" : "SoilTemperature_0.05mSensor1",
"Gauge" : "degC"
}
And I would like to change the complete collection (~ 90k items) to this, to conform to minimal GeoJson:
{
"_id" : ObjectId("5a5b2657a19692e18a3792ad"),
"Toponym" : "Climate station Stavenhagen",
"geometry" : {
"type" : "Point",
"coordinates" : [53.33333, 13.99999]
},
"SensorMaker": "Hitachi",
"SensorClass": "Thermometer",
"Dimension" : "SoilTemperature_0.05mSensor1",
"Gauge" : "degC"
}
I tried to convert it using this query, but whatever I do I will receive an error the like "Line 5: Unexpected string":
db.sensor_geo.aggregate([
{ '$group' : {
'_id' : '$_id',
'Toponym' : '$Toponym'
'geometry': { 'type': 'Point', { $set : {"coordinates.$[]": [ {'$Lat', '$Lon'} ] }}},
'SensorMaker' : '$SensorMaker',
'SensorClass' : '$SensorClass',
'Dimension' : '$Dimension',
'Gauge' : '$Gauge'
}
}
]);
Should I've used $push instead of $set, even though this also lead nowhere? Do I also have to create an ObjectID for the nested Object, and that may have caused the problem?