Skip to main content

Posts

Showing posts from December, 2014

Geospatial queries in MongoDB - Part 2 : {"err": "location object expected, location array not in correct format" "code": 16804}

In my last post we saw we had to create a geospatial index on the " pos " field as follows: > db.foodtrucks.ensureIndex({pos:"2d"}) However, when executing the command above we get the following error:   > db.foodtrucks.ensureIndex({pos:"2d"}) {     "createdCollectionAutomatically" : false,     "numIndexesBefore" : 3,     "ok" : 0,     "errmsg" : "location object expected, location array not in correct format",     "code" : 16804 } After some further investigation I realized that we had some documents which didn't had any latitude/longitude information. Due to this some of the documents looked like this: {     "_id" : ObjectId("53d07bf1e3e11dacc21056a8") ,     "locationid" : 437222 ,     "Applicant" : "Natan's Catering" ,     "FacilityType" : "Truck" ,     "cnn" : 188101 ,     "Locatio...

Geospatial queries in MongoDB - Part 1

While building a food truck service using which a user can browse and search for food options in a given area, I had to work with geographic latitude/longitude information. I was using MongoDB as my data store which supports geospatial queries. A sample document in my foodtruck collection looks like this: > db.foodtrucks.find().pretty().limit(1); {     "_id" : ObjectId("53d07bf1e3e11dacc2105697"),     "locationid" : 559777,     "Applicant" : "Mang Hang Catering",     "FacilityType" : "Truck",     "cnn" : 131000,     "LocationDescription" : "02ND ST: JESSIE ST to MISSION ST (69 - 99)",     "Address" : "85 02ND ST",     "blocklot" : 3708019,     "block" : 3708,     "lot" : 19,     "permit" : "14MFF-0109",     "Status" : "REQUESTED",     "FoodItems" : "...