Reputation: 45
I'm following this tutorial regarding how to import a GeoJSON file into my MongoDB. http://www.adityabansod.net/2014/11/
When I get to the command:
mongoimport --db sfstreets --collection streets < sweeping_clean.json
I get this error:
Failed: error processing document #2: invalid character ':' looking for beginning of value
Here's what the file looks like (or its first 3 rows):
"features": [
{ "type": "Feature", "properties": { "CNN": "13798000", "WEEKDAY": "Fri", "BLOCKSIDE": null, "BLOCKSWEEP": "1642922", "CNNRIGHTLE": "R", "CORRIDOR": "Corona St", "FROMHOUR": "12:00", "TOHOUR": "14:00", "HOLIDAYS": "N", "WEEK1OFMON": "Y", "WEEK2OFMON": "N", "WEEK3OFMON": "Y", "WEEK4OFMON": "N", "WEEK5OFMON": "N", "LF_FADD": "221", "LF_TOADD": "299", "RT_TOADD": "298", "RT_FADD": "222", "STREETNAME": "CORONA ST", "ZIP_CODE": "94127", "NHOOD": "Ingleside Terrace", "DISTRICT": null }, "geometry": { "type": "LineString", "coordinates": [ [ -122.466597727410232, 37.725924475312347 ], [ -122.466538207925296, 37.726008134595666 ], [ -122.466545014733981, 37.72609265587532 ], [ -122.466622699195298, 37.726149395842491 ], [ -122.466715781686275, 37.726165938701833 ], [ -122.466832802132032, 37.726142308565613 ], [ -122.466897677698327, 37.726061377866067 ], [ -122.466866500919153, 37.725977262576407 ], [ -122.4667409099483, 37.725929815795411 ], [ -122.466597727410232, 37.725924475312347 ] ] } },
{ "type": "Feature", "properties": { "CNN": "13576001", "WEEKDAY": "Fri", "BLOCKSIDE": "East", "BLOCKSWEEP": "1635302", "CNNRIGHTLE": "L", "CORRIDOR": "West Point Rd", "FROMHOUR": "09:00", "TOHOUR": "11:00", "HOLIDAYS": "N", "WEEK1OFMON": "Y", "WEEK2OFMON": "Y", "WEEK3OFMON": "Y", "WEEK4OFMON": "Y", "WEEK5OFMON": "Y", "LF_FADD": "1", "LF_TOADD": "199", "RT_TOADD": "198", "RT_FADD": "2", "STREETNAME": "WEST POINT RD", "ZIP_CODE": "94124", "NHOOD": "Hunters Point", "DISTRICT": null }, "geometry": { "type": "LineString", "coordinates": [ [ -122.380990296638643, 37.735956150208381 ], [ -122.380638929041751, 37.735578610786696 ], [ -122.380275721328843, 37.735358309670289 ], [ -122.379832804134111, 37.735239767490803 ], [ -122.379414567742032, 37.735244675031652 ] ] } },
Any idea what I'm doing wrong?
Upvotes: 0
Views: 1600
Reputation: 16
You should left array only in your JSON square brackets at the start and end of the file and --jsonArray parameter for mongoimport.
Upvotes: 0
Reputation: 2772
In meteorjs, wich uses mongodb, for import I use:
mongoimport -h localhost:3001 --db [DB] --collection [COLLECTION] --type json --file [data.json] --jsonArray
Dont know if it helps.
Upvotes: 1
Reputation: 45
I still don't really understand what the issue was, but I was able to find a workaround:
I created a script which stores each element of "features" inside an array, and inserts the array into the collection using db.<collection name>.insert(<array name>);
That did the trick for me and saved me a lot of manual labor.
Upvotes: 0