O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - finding nearby restaurants that serve burgers

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 and serves field of the restaurants 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" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required