SlideShare a Scribd company logo
MongoDB GeoSpatial
Feature
Hüseyin BABAL
@huseyinbabal
What is MongoDB GeoSpatial
Feature?
MongoDB allows you to create index and
queries to make operations on geospatial
(location information) data
In order to define index, or execute query, you
need to determine surface first
Surfaces
Spherical
To calculate geometry over an Earth-like
sphere, store your location data on a spherical
surface and use 2dsphere index.
MongoDB Reference
Store your location data as GeoJSON objects
with this coordinate-axis order: longitude,
latitude. The coordinate reference system for
GeoJSON uses the WGS84 datum.
MongoDB Reference
GeoJSON
Example Usage
Example Usage
Flat
To calculate distances on a Euclidean plane,
store your location data as legacy coordinate
pairs and use a 2d index.
MongoDB Reference
Query Operations
Inclusion
MongoDB can query for locations contained
entirely within a specified polygon. Inclusion
queries use the $geoWithin operator. No index
required, 2d and 2dsphere supports
MongoDB Reference
Intersection
MongoDB can query for locations that intersect
with a specified geometry. These queries apply
only to data on a spherical surface. These
queries use the $geoIntersects operator. Index
required, only 2dsphere supports
MongoDB Reference
Proximity
MongoDB can query for the points nearest to
another point. Proximity queries use the $near
operator. 2d or 2dsphere required
MongoDB Reference
Index Types
2d
● Calculations using flat geometry
● Legacy coordinate pairs (i.e., geospatial
points on a flat coordinate system)
● Compound indexes with only one additional
field, as a suffix of the 2d index field
2d Index Creation
db.collection.createIndex( { <location field> : "2d" } ,
{ min : <lower bound> , max : <upper bound> } )
db.collection.createIndex( { loc : "2d" } ,
{ min : -45 , max : 45 } )
2d Query
db.<collection>.find( { <location field> :
{ $geoWithin :
{ $box|$polygon|$center : <coordinates>
} } } )
db.places.find( { loc :
{ $geoWithin :
{ $box : [ [ 0 , 0 ] ,
[ 100 , 100 ] ]
} } } )
db.places.find( { loc: { $geoWithin :
{ $center : [ [-74, 40.74 ] , 10 ]
} } } )
db.<collection>.find( { <location field> :
{ $near : [ <x> , <y> ]
} } )
db.<collection>.find( { loc: [ <x> , <y> ] } )
2dsphere Index Creation
db.collection.createIndex( { <location field> : "2dsphere" } )
db.collection.createIndex( { loc : "2dsphere" } )
2dsphere Query
db.<collection>.find( { <location field> :
{ $geoWithin :
{ $geometry :
{ type : "Polygon" ,
coordinates : [ <coordinates> ]
} } } } )
db.places.find( { loc :
{ $geoWithin :
{ $geometry :
{ type : "Polygon" ,
coordinates : [ [[ 0 , 0 ] ,[ 3 , 6 ] ,[ 6 , 1 ] ,[ 0 , 0 ]] ]} } } } )
Intersection
db.<collection>.find( { <location field> :
{ $geoIntersects :
{ $geometry :
{ type : "<GeoJSON object type>" ,
coordinates : [ <coordinates> ]
} } } } )
db.places.find( { loc :
{ $geoIntersects :
{ $geometry :
{ type : "Polygon" ,
coordinates: [ [[ 0 , 0 ] ,[ 3 , 6 ] ,[ 6 , 1 ] ,[ 0 , 0 ]] ]} } } } )
Proximity
db.<collection>.find( { <location field> :
{ $near :
{ $geometry :
{ type : "Point" ,
coordinates : [ <longitude> , <latitude> ] } ,
$maxDistance : <distance in meters>
} } } )
2dsphere
● Calculations on a sphere
● GeoJSON objects and include backwards
compatibility for legacy coordinate pairs
● Compound indexes with scalar index fields
(i.e. ascending or descending) as a prefix or
geoHaystack
An index is a special index that is optimized to
return results over small areas. geoHaystack
indexes improve performance on queries that
use flat geometry.
Any Questions

More Related Content

PPTX
Getting Started with Geospatial Data in MongoDB
PPTX
Basics of MongoDB
PPTX
Mongodb basics and architecture
PPTX
Doing Joins in MongoDB: Best Practices for Using $lookup
PDF
MongoDB Schema Design (Richard Kreuter's Mongo Berlin preso)
KEY
JSON-LD: JSON for Linked Data
PDF
Working with JSON Data in PostgreSQL vs. MongoDB
KEY
JSON-LD and MongoDB
Getting Started with Geospatial Data in MongoDB
Basics of MongoDB
Mongodb basics and architecture
Doing Joins in MongoDB: Best Practices for Using $lookup
MongoDB Schema Design (Richard Kreuter's Mongo Berlin preso)
JSON-LD: JSON for Linked Data
Working with JSON Data in PostgreSQL vs. MongoDB
JSON-LD and MongoDB

What's hot (20)

PDF
Introduction to Mongodb execution plan and optimizer
PDF
MongoDB Aggregation Framework
PPTX
Mongo DB Presentation
PDF
Mongo DB schema design patterns
PPTX
JSON-LD for RESTful services
PPTX
Hadoop Pig
PPTX
MongoDB Aggregation Performance
PDF
Discover PostGIS: Add Spatial functions to PostgreSQL
 
PDF
Data Modeling with NGSI, NGSI-LD
PDF
Information retrieval to recommender systems
PDF
Indexing and Performance Tuning
PPTX
Indexing with MongoDB
PPT
Introduction to MongoDB
PPTX
MongoDB Schema Design: Practical Applications and Implications
PDF
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
PPTX
MongoDB - Aggregation Pipeline
PPT
Semantic Search Engines
PPTX
MongoDB
PDF
Apache HBase - Just the Basics
Introduction to Mongodb execution plan and optimizer
MongoDB Aggregation Framework
Mongo DB Presentation
Mongo DB schema design patterns
JSON-LD for RESTful services
Hadoop Pig
MongoDB Aggregation Performance
Discover PostGIS: Add Spatial functions to PostgreSQL
 
Data Modeling with NGSI, NGSI-LD
Information retrieval to recommender systems
Indexing and Performance Tuning
Indexing with MongoDB
Introduction to MongoDB
MongoDB Schema Design: Practical Applications and Implications
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB - Aggregation Pipeline
Semantic Search Engines
MongoDB
Apache HBase - Just the Basics
Ad

Similar to MongoDB GeoSpatial Feature (20)

PPTX
Open Source Mapping with Python, and MongoDB
PPT
TDC2016SP - Trilha NoSQL
KEY
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
KEY
Geospatial Indexing and Querying with MongoDB
PPTX
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
PDF
Mongoskin - Guilin
PDF
Geospatial Enhancements in MongoDB 2.4
KEY
OSCON july 2011
PPTX
Querying mongo db
PPT
Nosh slides mongodb web application - mongo philly 2011
PPT
Building Applications with MongoDB - an Introduction
PDF
The state of geo in ElasticSearch
PPT
Introduction to MongoDB
PPT
Building Your First MongoDB Application (Mongo Austin)
PDF
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
PPT
Building a web application with mongo db
PPTX
Building a Location-based platform with MongoDB from Zero.
PPTX
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
PPT
Building web applications with mongo db presentation
PDF
Geolocation on Rails
Open Source Mapping with Python, and MongoDB
TDC2016SP - Trilha NoSQL
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Geospatial Indexing and Querying with MongoDB
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Mongoskin - Guilin
Geospatial Enhancements in MongoDB 2.4
OSCON july 2011
Querying mongo db
Nosh slides mongodb web application - mongo philly 2011
Building Applications with MongoDB - an Introduction
The state of geo in ElasticSearch
Introduction to MongoDB
Building Your First MongoDB Application (Mongo Austin)
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
Building a web application with mongo db
Building a Location-based platform with MongoDB from Zero.
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Building web applications with mongo db presentation
Geolocation on Rails
Ad

More from Hüseyin BABAL (8)

PPTX
Infinite Scalable Systems with Docker
PPTX
NodeJS ve API Tasarım Temelleri
PPTX
RESTful API Design Fundamentals
PPTX
Token Based Authentication Systems with AngularJS & NodeJS
PPTX
Token Based Authentication Systems
PDF
Make Your Application Social
PDF
Realtime web applications with ExpressJS and SocketIO
PDF
Complete MVC on NodeJS
Infinite Scalable Systems with Docker
NodeJS ve API Tasarım Temelleri
RESTful API Design Fundamentals
Token Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems
Make Your Application Social
Realtime web applications with ExpressJS and SocketIO
Complete MVC on NodeJS

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
A Presentation on Artificial Intelligence
PPT
Teaching material agriculture food technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
A Presentation on Artificial Intelligence
Teaching material agriculture food technology
Chapter 3 Spatial Domain Image Processing.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.

MongoDB GeoSpatial Feature

  • 2. What is MongoDB GeoSpatial Feature?
  • 3. MongoDB allows you to create index and queries to make operations on geospatial (location information) data
  • 4. In order to define index, or execute query, you need to determine surface first
  • 6. Spherical To calculate geometry over an Earth-like sphere, store your location data on a spherical surface and use 2dsphere index. MongoDB Reference
  • 7. Store your location data as GeoJSON objects with this coordinate-axis order: longitude, latitude. The coordinate reference system for GeoJSON uses the WGS84 datum. MongoDB Reference
  • 11. Flat To calculate distances on a Euclidean plane, store your location data as legacy coordinate pairs and use a 2d index. MongoDB Reference
  • 13. Inclusion MongoDB can query for locations contained entirely within a specified polygon. Inclusion queries use the $geoWithin operator. No index required, 2d and 2dsphere supports MongoDB Reference
  • 14. Intersection MongoDB can query for locations that intersect with a specified geometry. These queries apply only to data on a spherical surface. These queries use the $geoIntersects operator. Index required, only 2dsphere supports MongoDB Reference
  • 15. Proximity MongoDB can query for the points nearest to another point. Proximity queries use the $near operator. 2d or 2dsphere required MongoDB Reference
  • 17. 2d ● Calculations using flat geometry ● Legacy coordinate pairs (i.e., geospatial points on a flat coordinate system) ● Compound indexes with only one additional field, as a suffix of the 2d index field
  • 18. 2d Index Creation db.collection.createIndex( { <location field> : "2d" } , { min : <lower bound> , max : <upper bound> } ) db.collection.createIndex( { loc : "2d" } , { min : -45 , max : 45 } )
  • 19. 2d Query db.<collection>.find( { <location field> : { $geoWithin : { $box|$polygon|$center : <coordinates> } } } ) db.places.find( { loc : { $geoWithin : { $box : [ [ 0 , 0 ] , [ 100 , 100 ] ] } } } )
  • 20. db.places.find( { loc: { $geoWithin : { $center : [ [-74, 40.74 ] , 10 ] } } } ) db.<collection>.find( { <location field> : { $near : [ <x> , <y> ] } } ) db.<collection>.find( { loc: [ <x> , <y> ] } )
  • 21. 2dsphere Index Creation db.collection.createIndex( { <location field> : "2dsphere" } ) db.collection.createIndex( { loc : "2dsphere" } )
  • 22. 2dsphere Query db.<collection>.find( { <location field> : { $geoWithin : { $geometry : { type : "Polygon" , coordinates : [ <coordinates> ] } } } } ) db.places.find( { loc : { $geoWithin : { $geometry : { type : "Polygon" , coordinates : [ [[ 0 , 0 ] ,[ 3 , 6 ] ,[ 6 , 1 ] ,[ 0 , 0 ]] ]} } } } )
  • 23. Intersection db.<collection>.find( { <location field> : { $geoIntersects : { $geometry : { type : "<GeoJSON object type>" , coordinates : [ <coordinates> ] } } } } ) db.places.find( { loc : { $geoIntersects : { $geometry : { type : "Polygon" , coordinates: [ [[ 0 , 0 ] ,[ 3 , 6 ] ,[ 6 , 1 ] ,[ 0 , 0 ]] ]} } } } )
  • 24. Proximity db.<collection>.find( { <location field> : { $near : { $geometry : { type : "Point" , coordinates : [ <longitude> , <latitude> ] } , $maxDistance : <distance in meters> } } } )
  • 25. 2dsphere ● Calculations on a sphere ● GeoJSON objects and include backwards compatibility for legacy coordinate pairs ● Compound indexes with scalar index fields (i.e. ascending or descending) as a prefix or
  • 26. geoHaystack An index is a special index that is optimized to return results over small areas. geoHaystack indexes improve performance on queries that use flat geometry.