We are going to refine our earlier example to look for nearby eateries that serve burgers and display them on the map. Let's see how we can do that:
1. In the
mongo
shell, enter the following commands to build a geospatial haystack index for the location andserves
field of therestaurants
collection:> use geolocation switched to db geolocation > db.restaurants.ensureIndex({location:"geoHaystack", serves:1},{bucketSize : 1})
2. Create a file named
haystack.html
and put the following code in it:<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" href="styles.css"/> <style type="text/css" media="screen"> div#map { width:450px; height: 400px; } </style> <title>Burger place near me</title> </head> <body> <div id="contentarea"> <div id="innercontentarea...