{"id":1610,"date":"2014-11-21T14:15:18","date_gmt":"2014-11-21T12:15:18","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=1610"},"modified":"2014-11-21T20:31:55","modified_gmt":"2014-11-21T18:31:55","slug":"efficiently-paging-geospatial-data-with-mongodb","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/","title":{"rendered":"Efficiently Paging Geospatial Data With MongoDB"},"content":{"rendered":"<p>From release 2.6, MongoDB includes a new <code>minDistance<\/code> option for geospatial queries.<\/p>\n<p>This is exciting because it lets you page through geospatial results very efficiently, and because it&#8217;s the first feature I&#8217;ve contributed to the database itself.<\/p>\n<p>I&#8217;ll measure how <code>minDistance<\/code> performs and show you an example app.<\/p>\n<h2>Better, Faster<\/h2>\n<p>I&#8217;m going to fill a MongoDB collection with the locations of sidewalk caf\u00e9s in NYC, and declare a <code>2dsphere<\/code> index on those locations. In Python:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">from pymongo import MongoClient\r\ndb = MongoClient().test\r\ndb.cafes.insert({\r\n    'Entity Name': 'Cafe Mocha, Inc.',\r\n    'Sidewalk Cafe Type': 'Unenclosed',\r\n    'Street Address': '116 2 Avenue',\r\n    'location': {\r\n        'type': 'Point',\r\n        'coordinates': &#x5B;\r\n            -73.98817410082268,\r\n            40.72788705499784\r\n        ],\r\n    }\r\n})\r\n\r\ndb.cafes.create_index(&#x5B;\r\n    ('location', '2dsphere')])<\/pre>\n<p>I have info for 1008 caf\u00e9s from <a href=\"https:\/\/data.cityofnewyork.us\/\">NYC Open Data<\/a>. Now I can query for the ten caf\u00e9s nearest Union Square:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">result = db.command(\r\n    'geoNear', 'cafes',\r\n    near={\r\n        'type': 'Point',\r\n        'coordinates': &#x5B;\r\n            -73.991084,\r\n            40.735863]},\r\n    spherical=True,\r\n    num=10)<\/pre>\n<p>MongoDB returns them to me sorted from nearest to farthest. The problems start if I want the <strong>next<\/strong> 10 results. MongoDB doesn&#8217;t support <code>skip<\/code> with geo queries. I can simulate it with the aggregation framework. I query for 20 caf\u00e9s and filter out the first 10 with the aggregation framework&#8217;s <code>$skip<\/code> operator:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">result = db.cafes.aggregate(&#x5B;{\r\n    '$geoNear': {\r\n        'near': {\r\n            'type': 'Point',\r\n            'coordinates': &#x5B;\r\n                -73.991084,\r\n                40.735863]},\r\n        'spherical': True,\r\n        'distanceField': 'dist',\r\n        'num': 20}\r\n}, {\r\n    '$skip': 10\r\n}])<\/pre>\n<p>This trick (from my colleague <a href=\"http:\/\/www.kamsky.org\/stupid-tricks-with-mongodb.html\">Asya Kamsky<\/a>) lets me page through geo results, but it gets slower with bigger skip values. I timed it on a collection of 10,000 random locations:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/skip-performance-copy.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1631\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/skip-performance-copy.jpg\" alt=\"skip-performance copy\" width=\"850\" height=\"531\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/skip-performance-copy.jpg 850w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/skip-performance-copy-300x187.jpg 300w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><\/p>\n<p>As the <code>$skip<\/code> number grows from zero to 10,000, the duration grows linearly, even though the query always returns 10 results. After all, in order to get those 10 documents, MongoDB must find all the prior documents and pass them through the aggregation pipeline, only to discard them at the <code>$skip<\/code> phase.<\/p>\n<p>Paging through geo results is obviously useful, so how do we do it efficiently? MongoDB 2.6 comes with a new <code>minDistance<\/code> option for geospatial queries. This is my first contribution to MongoDB&#8217;s C++ code\u2014generally I work on Python. Hold your applause, please: I just wired together some mechanisms built by minds greater than mine, and even so I needed a lot of handholding from <a href=\"https:\/\/twitter.com\/whitewhalechef\">Hari Khalsa<\/a>. However simple the feature was to implement, it makes paging through geo results much faster.<\/p>\n<p>Here&#8217;s how to page with <code>minDistance<\/code>. I query for the first 10 locations normally. When I want the next 10 locations, I set <code>minDistance<\/code> to the farthest distance I&#8217;ve seen so far. So if my 10th result is 268 meters away and has id 42:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">{\r\n    'dis': 268,\r\n    'obj': {\r\n        '_id': 42,\r\n        'Entity Name': 'LM Restaurant Group',\r\n        'Street Address': '120 East 15 Street',\r\n        'location': {\r\n            'type': 'Point',\r\n            'coordinates': &#x5B;\r\n                -73.98834760821919,\r\n                40.73463761939186\r\n             ]\r\n         }\r\n     }\r\n}<\/pre>\n<p>&#8230; then I set <code>minDistance<\/code> to 268 and query for the next 10 documents. I must also exclude this document&#8217;s id to avoid seeing it again in the next batch, since <code>minDistance<\/code> is inclusive.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">ids = &#x5B;42]\r\n\r\nresult = db.command(\r\n    'geoNear', 'cafes',\r\n    near={\r\n        'type': 'Point',\r\n        'coordinates': &#x5B;\r\n            -73.991084,\r\n            40.735863]},\r\n    spherical=True,\r\n    minDistance=268,\r\n    query={\r\n        '_id': {\r\n            '$nin': ids}},\r\n    num=10)<\/pre>\n<p>The farthest document from the first batch is excluded using a &#8220;not in&#8221; (<code>$nin<\/code>) query. If several documents are equally far away, I&#8217;d exclude all their ids. This technique performs quite well on my random collection:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/minDistance-performance-copy.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1632\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/minDistance-performance-copy.jpg\" alt=\"minDistance-performance copy\" width=\"850\" height=\"531\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/minDistance-performance-copy.jpg 850w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/minDistance-performance-copy-300x187.jpg 300w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><\/p>\n<p>The first batch performs the same as it did with the aggregation framework, but the final batch takes one tenth the time with <code>minDistance<\/code> as it did with <code>$skip<\/code>: 170ms instead of 1.6 seconds.<\/p>\n<h2>An Example App<\/h2>\n<p>Paging with <code>minDistance<\/code> requires some futzy code, compared to the straightforward aggregation technique. To work out the kinks, I made an example app with my sidewalk-caf\u00e9 data. You can play with it here:<\/p>\n<p><a href=\"http:\/\/emptysqua.re\/geopaging\" target=\"_blank\">http:\/\/emptysqua.re\/geopaging<\/a><\/p>\n<p>The app uses PyMongo, Flask, and MongoDB. To start, enter a location dense with sidewalk caf\u00e9s, like my zipcode &#8220;10009&#8221;. The app asks Google for the coordinates of your location, and shows you the 10 nearest caf\u00e9s:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-table.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1633\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-table.jpg\" alt=\"sidewalk-cafes-table\" width=\"850\" height=\"485\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-table.jpg 850w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-table-300x171.jpg 300w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-screenshot.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1634\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-screenshot.jpg\" alt=\"sidewalk-cafes-screenshot\" width=\"850\" height=\"385\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-screenshot.jpg 850w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/sidewalk-cafes-screenshot-300x135.jpg 300w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><\/p>\n<p>As you click Next, some Javascript asks the server-side application for the next 10 points. The script keeps track of the farthest distance it has seen so far, and passes that distance to the server when it asks for the next batch. You can see the ring of caf\u00e9s move outwards from the center-point as <code>minDistance<\/code> increases.<\/p>\n<p>When the script asks the server for the next batch, it also passes the ids of all documents at the current farthest distance, and the server excludes them. Normally this exclusion-list has just one id: the id of the last point retrieved. But the city&#8217;s data has some bugs. There are 14 caf\u00e9s with the same geocoordinates, despite distinct addresses. Bruno The King Of Ravioli, for example, is twelve blocks from my beloved Benny&#8217;s Burritos, but they&#8217;re listed at the same (wrong) geocoordinates on 10th Street near Avenue B. Since they&#8217;re at the same coordinates, they have the same distance from your center point. Paging through such data using <code>minDistance<\/code> requires a careful algorithm. In pseudo-Python:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">min_distance = 0\r\nlast_ids = &#x5B;]\r\n\r\ndef get_batch():\r\n    global min_distance, last_ids\r\n\r\n    result = db.command(\r\n        'geoNear', 'cafes',\r\n        near=center_point,\r\n        spherical=True,\r\n        minDistance=min_distance,\r\n        query={\r\n            '_id': {'$nin': last_ids}\r\n        },\r\n        num=10)\r\n\r\n    results = result&#x5B;'results']\r\n    if not results:\r\n        # Finished.\r\n        return &#x5B;]\r\n\r\n    # Last result is farthest.\r\n    new_min_distance = result&#x5B;-1]&#x5B;'dis']\r\n\r\n    if new_min_distance == min_distance:\r\n        # We're still paging through results\r\n        # all at same distance as previous\r\n        # farthest. Append to last_ids.\r\n        last_ids += &#x5B;\r\n            r&#x5B;'obj']&#x5B;'_id'] for r in results]\r\n    else:\r\n        # Results in this page are farther\r\n        # than previous page.\r\n        # Replace last_ids.\r\n        min_distance = new_min_distance\r\n        last_ids = &#x5B;\r\n            r&#x5B;'obj']&#x5B;'_id']\r\n            for r in result&#x5B;'results']\r\n            if r&#x5B;'dis'] == min_distance]\r\n\r\n    return results<\/pre>\n<p>This takes care of paging forward from the nearest 10 caf\u00e9s to the farthest. How do we go backwards? Unfortunately, the <code>geoNear<\/code> command doesn&#8217;t support searching inward from a <code>maxDistance<\/code>: it always iterates from near to far. My solution is simply to cache results as I retrieve them. So when you click Previous in my app, it shows you the previous page from the results it keeps in memory. If you hit Next again, the app checks whether it has the next page of results cached, and if so avoids the round trip to the server.<\/p>\n<h2>What&#8217;s Next?<\/h2>\n<p>Check out my application on GitHub; the most interesting code is the server-side <a href=\"https:\/\/github.com\/ajdavis\/geo-paging-example\/blob\/master\/server.py#L50\">results() function<\/a> which runs the <code>geoNear<\/code> command, and the Javascript <a href=\"https:\/\/github.com\/ajdavis\/geo-paging-example\/blob\/master\/static\/near.js#L23\">getMoreRows() function<\/a> which implements the paging algorithm. Install the <a href=\"http:\/\/www.mongodb.org\/downloads\">current production release of MongoDB<\/a>, make something cool with geo data, and <a href=\"https:\/\/twitter.com\/jessejiryudavis\">let me know<\/a>.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/emptysqua.re\/blog\/paging-geo-mongodb\/\">Efficiently Paging Geospatial Data With MongoDB<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/wcg\/\">WCG partner<\/a> Jesse Davis at the <a href=\"http:\/\/emptysqua.re\/blog\/\">A. Jesse Jiryu Davis<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>From release 2.6, MongoDB includes a new minDistance option for geospatial queries. This is exciting because it lets you page through geospatial results very efficiently, and because it&#8217;s the first feature I&#8217;ve contributed to the database itself. I&#8217;ll measure how minDistance performs and show you an example app. Better, Faster I&#8217;m going to fill a &hellip;<\/p>\n","protected":false},"author":29,"featured_media":1650,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[57],"class_list":["post-1610","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nosql","tag-mongodb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Efficiently Paging Geospatial Data With MongoDB - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"From release 2.6, MongoDB includes a new minDistance option for geospatial queries. This is exciting because it lets you page through geospatial results\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Efficiently Paging Geospatial Data With MongoDB - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"From release 2.6, MongoDB includes a new minDistance option for geospatial queries. This is exciting because it lets you page through geospatial results\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-11-21T12:15:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-21T18:31:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jesse Davis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/jessejiryudavis\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jesse Davis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/\"},\"author\":{\"name\":\"Jesse Davis\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/294d6819cb410ef55f273ecf25426c56\"},\"headline\":\"Efficiently Paging Geospatial Data With MongoDB\",\"datePublished\":\"2014-11-21T12:15:18+00:00\",\"dateModified\":\"2014-11-21T18:31:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/\"},\"wordCount\":1091,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg\",\"keywords\":[\"MongoDB\"],\"articleSection\":[\"NoSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/\",\"name\":\"Efficiently Paging Geospatial Data With MongoDB - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg\",\"datePublished\":\"2014-11-21T12:15:18+00:00\",\"dateModified\":\"2014-11-21T18:31:55+00:00\",\"description\":\"From release 2.6, MongoDB includes a new minDistance option for geospatial queries. This is exciting because it lets you page through geospatial results\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"NoSQL\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/nosql\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Efficiently Paging Geospatial Data With MongoDB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/294d6819cb410ef55f273ecf25426c56\",\"name\":\"Jesse Davis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2db0fdaadd8cd6b86d93e1205e30dd3b43e3c46b91826513ab618934c3db8cf9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2db0fdaadd8cd6b86d93e1205e30dd3b43e3c46b91826513ab618934c3db8cf9?s=96&d=mm&r=g\",\"caption\":\"Jesse Davis\"},\"description\":\"Jesse is a senior engineer at MongoDB in New York City. He specializes in Python, MongoDB drivers, and asynchronous frameworks.\",\"sameAs\":[\"http:\/\/emptysqua.re\/blog\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/jessejiryudavis\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/jesse-davis\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Efficiently Paging Geospatial Data With MongoDB - Web Code Geeks - 2026","description":"From release 2.6, MongoDB includes a new minDistance option for geospatial queries. This is exciting because it lets you page through geospatial results","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/","og_locale":"en_US","og_type":"article","og_title":"Efficiently Paging Geospatial Data With MongoDB - Web Code Geeks - 2026","og_description":"From release 2.6, MongoDB includes a new minDistance option for geospatial queries. This is exciting because it lets you page through geospatial results","og_url":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2014-11-21T12:15:18+00:00","article_modified_time":"2014-11-21T18:31:55+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg","type":"image\/jpeg"}],"author":"Jesse Davis","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/jessejiryudavis","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Jesse Davis","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/"},"author":{"name":"Jesse Davis","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/294d6819cb410ef55f273ecf25426c56"},"headline":"Efficiently Paging Geospatial Data With MongoDB","datePublished":"2014-11-21T12:15:18+00:00","dateModified":"2014-11-21T18:31:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/"},"wordCount":1091,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg","keywords":["MongoDB"],"articleSection":["NoSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/","url":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/","name":"Efficiently Paging Geospatial Data With MongoDB - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg","datePublished":"2014-11-21T12:15:18+00:00","dateModified":"2014-11-21T18:31:55+00:00","description":"From release 2.6, MongoDB includes a new minDistance option for geospatial queries. This is exciting because it lets you page through geospatial results","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/mongodb-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/nosql\/efficiently-paging-geospatial-data-with-mongodb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"NoSQL","item":"https:\/\/www.webcodegeeks.com\/category\/nosql\/"},{"@type":"ListItem","position":3,"name":"Efficiently Paging Geospatial Data With MongoDB"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/294d6819cb410ef55f273ecf25426c56","name":"Jesse Davis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2db0fdaadd8cd6b86d93e1205e30dd3b43e3c46b91826513ab618934c3db8cf9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2db0fdaadd8cd6b86d93e1205e30dd3b43e3c46b91826513ab618934c3db8cf9?s=96&d=mm&r=g","caption":"Jesse Davis"},"description":"Jesse is a senior engineer at MongoDB in New York City. He specializes in Python, MongoDB drivers, and asynchronous frameworks.","sameAs":["http:\/\/emptysqua.re\/blog\/","https:\/\/x.com\/https:\/\/twitter.com\/jessejiryudavis"],"url":"https:\/\/www.webcodegeeks.com\/author\/jesse-davis\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=1610"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1610\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/1650"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=1610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=1610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=1610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}