SVCC 13 - Polyglot Spatial with MongoDB and OpenShift


http://talks.thesteve0.com

Presented by:

Steven Pousty

@TheSteve0 on Twitter, IRC, and Github

Agenda

  1. A little about MongoDB Spatial
  2. Learn a bit about PaaS
  3. See some demos

Assumptions

  1. You have worked with datas
  2. You write some code
  3. You will ask questions

Types of NoSQL datastores

TYPEDocumentKey-ValueGraphData ProcessingMisc
EXAMPLE MongoDB, Couchbase Redis, Riak, Memcahe Neo4J Hadoop, Cassandra, Voldemort Lucene/Solr/ElasticSearch, VoltDB
USE-CASE Document storage and search Caching or Object Store Relationships between "things" Large data processing Depends

On to Mongo

 

A bit about MongoDB

  • A document is just a bunch of attributes and values - think of it like HashMap
  • Can be nested - helps avoid joins
  • Schemaless
  • Really good at fast writes - but you give up immediate consistency
  • Easy to horizontally scale

Now some spatial

The spatial functionality Mongo currently has is:

  1. Near ($near)
  2. Containment ($geoWithin)
  3. Intersection ($geoIntersects )


It is all laid out here:

Geospatial Indexes and Queries

and here:

Geospatial Index Internals

Two types of indices:

  1. 2D - for flat surfaces
  2. 2dsphere - helps with coords on an earth like sphere

Good to Know

  • Assumes coords. are between [-180 and 180)
  • Can handle any 2D coordinates
  • Has methods to handle curvature of the earth (spherical)
  • Formula to convert to human readable units

How do you make it work

1. Put coordinates into an array


{ loc : [ 50 , 30 ] }
{ loc : { x : 50 , y : 30 } }
{ loc : { foo : 50 , y : 30 } }
{ loc : { lon : 40.739037, lat: 73.992964 } }
                    
                    If you use lattitude and longitude with a default index make sure to put [lon, lat]
				    

2. Make a 2D index


				    	db.places.ensureIndex( { loc : "2d" } )
				    

Let's look at some code

Build a spatial checkin service for national parks in US and Canada

  1. Java - JEE using CDI and JAX-RS
  2. Python - Using Flask
  3. Node.JS - using Express
  4. Full Java with Leaflet Frontend

The full map front end app can be found here http://javaparks-sipsummit.rhcloud.com - it may take a while to spin the application back up if nobody has visited in a while

Let's spin up a Python and MongoDB server

One Source to Bind Them All


 

 

But wait - there's more

  1. Free! No time limit
  2. 3 gears (like servers) - each 512 Mb RAM, 1 Gb disk
  3. Auto-scaling
  4. Simple pricing

Let's wrap it up

  1. Openshift makes life great for you
  2. Spatial is easy and fun with MongoDB
  3. Free!

Come hang out with us:
#openshift on freenode irc
OR
users@lists.openshift.redhat.com