Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB: Location based applications

MongoDB: Location based applications

Avatar for Vitaly Domnikov

Vitaly Domnikov

February 26, 2013
Tweet

Other Decks in Programming

Transcript

  1. GEOSPATIAL INDEXES WE NEED DATA FIELD AND INDEX l o

    c a t i o n : [ x , y ] l o c a t i o n : { x : 1 , y : 2 } d b . a t m s . e n s u r e I n d e x ( { ' l o c a t i o n ' : ' 2 d ' } )
  2. PROXIMITY QUERIES d b . a t m s .

    f i n d ( { l o c a t i o n : { $ n e a r : [ - 7 0 , 4 0 ] } } ) d b . r u n C o m m a n d ( { g e o N e a r : " a t m s " , n e a r : [ x , y ] } )
  3. QUERIES RESULTS { " n s " : " t

    e s t . p l a c e s " , " r e s u l t s " : [ { " d i s " : 3 , " o b j " : { " _ i d " : O b j e c t I d ( " . . . " ) , " l o c a t i o n " : [ - 7 3 , 3 9 ] } } ] , . . . }
  4. DISTANCE QUERIES d b . a t m s .

    f i n d ( { l o c a t i o n : { $ n e a r : [ - 7 0 , 4 0 ] , $ m a x D i s t a n c e : 2 0 } } ) d b . r u n C o m m a n d ( { g e o N e a r : " a t m s " , n e a r : [ x , y ] , $ m a x D i s t a n c e : 2 0 } )
  5. SPHERICAL GEOMETRY f i n d ( . . $

    n e a r S p h e r e . . ) f i n d ( . . $ c e n t e r S p h e r e . . ) g e o N e a r ( . . { s p h e r i c a l : t r u e } . . )
  6. DISTANCE MULTIPLIER d b . r u n C o

    m m a n d ( { g e o N e a r : " a t m s " , n e a r : [ - 7 4 , 4 0 . 7 4 ] , s p h e r i c a l : t r u e , d i s t a n c e M u l t i p l i e r : 6 3 7 8 . 1 3 7 } )
  7. CIRCLES d b . a t m s . f

    i n d ( { " l o c a t i o n " : { " $ w i t h i n " : { " $ c e n t e r " : [ [ - 7 4 , 4 0 . 7 4 ] , 1 0 ] } } } )
  8. RECTANGLES d b . a t m s . f

    i n d ( { " l o c a t i o n " : { " $ w i t h i n " : { " $ b o x " : [ [ - 7 4 , 4 0 . 7 4 ] ] } } } )
  9. POLYGONS d b . a t m s . f

    i n d ( { " l o c a t i o n " : { " $ p o l y g o n " : { " $ b o x " : [ [ 0 , 0 ] , [ 3 , 3 ] , [ 6 , 0 ] ] } } } )
  10. EXACT QUERIES d b . a t m s .

    f i n d ( { " l o c a t i o n " : [ [ - 7 4 , 4 0 . 7 4 ] ] } )