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)
3. 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/long
use Google’s MAP API to find lat/long
build a 2d index (lat/long)
db.collection.ensureIndex({field:”2d”});
let the geospatial queries begin!
5. Pulse
Help people in emergency situations
Find the closest hospital
Notify important contacts (immediate family, friends, primary care physician, etc)
Provide real-time updates of your location to hospital and contacts
Extra features that would make this app rock!
Send pictures to hospital
Get ER wait times
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
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
7. Import into MongoDB
mongoimport --headerline --type csv --drop --db
mongodc --collection hospitals --file Outcome of Care
Measures.csv
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”
“$within can be used instead of $near to find items within a shape. At the moment, $box
(rectangles) and $center (circles) are supported.”
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 pymongo Drivers!
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 Queries
geoNear (gives you back the distance :-) )
$near vs. $nearSphere (1.7.0)
db.hospitals.find({"loc": {"$nearSphere":
[38.890389,-77.084144]}})
$within [box,center]
Results are sorted by distance away from points