Mongo sf spatialmongo

13
1 Get your Spatial on with MongoDB in the Cloud Steven Citron-Pousty PaaS Dust Spreader, Red Hat

Transcript of Mongo sf spatialmongo

Page 1: Mongo sf spatialmongo

1

Get your Spatial on withMongoDB in the Cloud

Steven Citron-PoustyPaaS Dust Spreader, Red Hat

Page 2: Mongo sf spatialmongo

2

Agenda

• Learn a little spatial

• Load some spatial data into MongoDB

• Do a query or two

• Show some server-side code using it

• MAKE YOU A ROCKSTAR!!

Page 3: Mongo sf spatialmongo

3

1) You can use the command line

2) You are comfortable with MongoDB command line

3) Please ask questions – though since we only have 30 minutes they may have to wait until the end or after the session

Assumptions

Page 4: Mongo sf spatialmongo

4

What is OpenShift?

Red Hat's free, auto-scaling Platform as a Service (PaaS) for applications in the cloud.

Page 5: Mongo sf spatialmongo

5

Kind of like Amazon, right? Nope.

Page 6: Mongo sf spatialmongo

6

What’s supported?

Page 7: Mongo sf spatialmongo

7

Looks great, but what’s the catch?

• OpenShift is free-as-in-beer & free-as-in-freedom

• Three 1.5 GB RAM / 3 GB storage gears

• Need more resources, just ask!

• We are in Developer Preview

Page 8: Mongo sf spatialmongo

8

On to Spatial and MongoDB

Page 9: Mongo sf spatialmongo

9

The only spatial functionality MongoDB currently has is:

1) Near

2) Containment

All of it is laid out on one page:

http://www.mongodb.org/display/DOCS/Geospatial+Indexing

First link on a google search for “MongoDB spatial indexing”

Spatial is fun!

Page 10: Mongo sf spatialmongo

10

1. Assumes coordinates are between -180 and 180

2. Can handle any 2d coordinates

3. Has methods to handle curvature of the earth (spherical)

Caveats

Page 11: Mongo sf spatialmongo

11

1) Put your coordinates into an arrary{ loc : [ 50 , 30 ] } //SUGGESTED OPTION

{ loc : { x : 50 , y : 30 } }

{ loc : { foo : 50 , y : 30 } }

{ loc : { lon : 40.739037, lat: 73.992964 } }

1) Make a 2d index

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

How to make it work

Page 12: Mongo sf spatialmongo

12

1. I have an app and a MongoDB instance running

2. Load some spatial data in JSON format

3. Make the 2d index

4. Do a bunch of command you would need in building an app (except Deleting docs, because that is easy cheezy)

Demo

Page 13: Mongo sf spatialmongo

13

1. Spatial is easy and fun on MongoDB!

2. You can now build your own FourSquare or other check-in application.

3. You can also build your own field data entry system.

4. You can build and deploy your application quickly without having to think about infrastructure.

Conclusion