mapmeld / mapplz-go

Make mapping quick and easy in different languages with MapPLZ
http://mapplz.com
43 stars 3 forks source link

Mongodb combined index #4

Open supafoundation opened 10 years ago

supafoundation commented 10 years ago

Hi, does mapplz allow creating a combined index? If so, could you please include an example?

It will be much appreciated.

Thanks

mapmeld commented 10 years ago

MapPLZ is using MongoDB and its Go driver, mgo. There is some documentation on how to create indexes using mgo here: http://godoc.org/labix.org/v2/mgo#Index but they do not mention combined index specifically.

MapPLZ uses a 2dsphere index on the geo.geometry property, but only in more advanced geospatial queries like near point and within polygon.

In your case, why not create a combined index once in MongoDB? You can use any tool to create the database - MapPLZ is just reading and writing to it. I don't see why this would cause a problem.

supafoundation commented 10 years ago

Thanks for the quick reply. I noticed this moments later. Can I ask if geonear and geowithin is supported? I tried looking at source code but can't find it.

I need a way to find nearby places from a point

mapmeld commented 10 years ago

"near" and "within" are generic names used for all of the available databases. A good place to see how queries are implemented with MongoDB is https://github.com/mapmeld/mapplz-go/blob/master/mapdb_mongo.go

You can see the "near" function uses MongoDB's nearSphere, and "within" uses MongoDB's geoWithin. I don't expect the average user to know how each database works - I just choose a simple name for the function