MongoDB and GeoJSON - Pro Tip!

Well, I'm no expert but here's a tip that might save you some time. I have a Drupal databae outputting valid GeoJSON data. Our data looks like this:

{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-122.0570486784,
36.99607280576
]
},
"properties": {
"name": "Dean of Students Office",
"description": null,
"Food Type": "",
"Item Type": "Student Services",
"Parking Type": "",
"Seated Capacity": null,
"Standing Capacity": null
}
}
 
The data loads correctly via mongoimport. If you don't see the problem, you will. MongoDB is based on javascript and js wants properties labelled with camelCase. So, the data needs to actually look like this next block. The solution is to do some find and replace using your favorite text editor, then drop the collection and re-import it.
 
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-122.0570486784,
36.99607280576
]
},
"properties": {
"name": "Dean of Students Office",
"description": null,
"foodType": "",
"itemType": "Student Services",
"parkingType": "",
"seatedCapacity": null,
"standingCapacity": null
}
}
 

Add new comment

By submitting this form, you accept the Mollom privacy policy.