2. MongoDB Is Easy! Document Object Store JSON (BSON) Schema-less Multiple language support (c++ to python to nodejs) Easy-to-Scale (http://www.mongodb.org/display/DOCS/Production+Deployments) Support for geospatial indexing and queries
4. Pulse Help people in emergency situations Find the closest hospital Notify important contacts (immediate family, friends, primary care physician, etc) Extra features that would make this app rock! Provide real-time updates of your location to hospital and contacts Send pictures to hospital Get ER wait times (this data is available in some states) Notify hospital of important medical information: blood-type, allergies, current medications, EMR, etc (integrate with google health/careverge) Integrate with 3rd party devices (watches, wristbands, etc) that know your vitals such as: blood pressure and heart rate. Transmit to your smart phone and then to hospital and contacts
5. LBS w/MongoDB Get or collect some location data (addresses are fine) Store it in mongoDB if data is in tsv/csv/json use mongoimport find lat/lng if you don’t already have it use Google’s MAP API to find lat/long if you have an address build a 2d index (lat/lng) db.collection.ensureIndex({field:”2d”}); let the geospatial queries begin!
6. Get Some Data Location of Hospitals In The United States Medicare.gov has information about the quality of care at each hospital - this data also happens to include the address for over 4000 hospitals in the US
8. Geospatial Indexing db.places.ensureIndex({loc:”2d”}); / (compounded indexes): db.places.ensureIndex( { loc : "2d" , category : 1 } ); Geohash is calculated and stored in a B-Tree Sharding Capable (as of 1.7.2 - Thanks Mathias - from 10gen) Current Limitations “Doesn’t currently handle wrapping at the poles or at the transition from -180° to +180° longitude, however we detect when a search would wrap and raise an error” (Resolved in 1.9+) Need to use geoNear command instead of $near for now when sharding (see JIRA SERVER-1981) - Proposed for resolution in 2011 geoNear not in the pymongoDrivers! Eval Hack - http://permalink.gmane.org/gmane.comp.db.mongodb.user/67 (Thanks smsfail on #mongodb) eval_result = db.eval('db.runCommand( { geoNear : "location" , near :[%s,%s], num : %s } );' % (lat, lon, num)) results = eval_result.get('results', []) Do not shard on a geo key - works, but inefficient. See JIRA SERVER-1982.
9. Geospatial Querying geoNeargives you back the distance (in radians if sphere=true) Results are sorted by distance away from points $near vs. $nearSphere (1.7.0) $within [box, center, polygon] instead of $near Not sorted by distance More examples and details on the wiki
Today I’m going to be talking about building location aware applications with mongodb
If you’re new to mongodb, there are various reasons for why you may want to choose it as your database, but today I’m going to focus on its support for working with geospatial data
I was planning on just pulling up the mongo shell and going through some geo commandsBut that would be boring and you’d learn more from the wiki anyway, so I decided to actually build an app that would show case some of mongo’s geo capabilitiesI made a mobile app called Pulse that utilizes the technologies you see on this pageWe will touch up on how each of these is used later on
I use to work for a healthcare startup in DC and so I wanted to build something around health that was immediately useful to the end user
So, let’s get started with what it takes to build an app like pulse
Ok, so back to pulse
By geohashing we transform the 2d search problem back into a 1d search problem, which is what B-tree indexes are good at.The geo-index of MongoDB encodes a geohash on top of a standard MongoDB b-tree. Geohashing is a way to divide a coordinate system into hierarchical buckets of grid shape.It basically divides an area in two for every bit and so on.A drawback of geohashing is the wrapping (-180 and 179 are very close for example), this can be solved by doing a grid search after the initial scan. It’s a bit comparable by how google maps loads the map images, it starts with the center of the viewport and then the surrounding areas are downloaded.