I have an Access 2010 database with information from Geonames. The table name is cities. For simplicity the columns are “name”, “latitude”, “longitude”, “loc”. I created “loc” to combine “longitude” and “latitude” into one field so that I can use MongoDB’s geospatial index. I had to save the “loc” column in string format since I am combining two decimal values with a comma in between.
When I export this table to a CSV I skip “longitude” and “latitude” since I have the new combined “loc” field.
The CSV looks like:
"geonameid", "name", "loc"
1, "Sweden", "18.068287,59.336341"
After I run MongoImport into “cities” collection, the loc field is embraced with quotation marks such as:
{ "_id" : ObjectId("50a9ed157db1bcfe22cddd0a"), "geonameid" : 20, "name" : "Sweden", "loc" : "18.068287,59.336341", }
From here I run a command to turn “loc” into an array. I use the following command thanks to another contributor here on Stackoverflow:
db.cities.find( { 'loc' : {$type : 2 } } ).forEach( function (x) { x.loc = new Array(x.loc); db.cities.save(x); });
The result is:
{ "_id" : ObjectId("50a9ed157db1bcfe22cddd0a"), "geonameid" : 20, "name" : "Sweden", "loc" : [ "18.068287,59.336341" ], }
How can I remove the quotation marks from my gps coordinates in the “loc” field? I can’t code in java and don’t mind waiting for MongoDB to perform this task. If it would work to export the CSV with the “longitude” and “latitude” fields and combine them into a new “loc” field in MongoDB I don’t mind that either even if it is not a beautiful solution. I just need to get the “loc” field working with the geospatial index.
You combined numbers into “loc” fild so now it’s a string and it’s being quoted. Separate it back to numbers before importing into MongoDB.
But you need “loc” field to be an array to use it with GEOindex – and arrays aren’t possible with CSV. You need to find a way to export data from MS Access to JSON and then import JSON to MongoDB with “
mongoimport --jsonArray” commandExporting Access to JSON – http://www.divconq.com/2010/export-a-microsoft-access-database-to-json/