title: MongoDB - Whats wrong with how I create index?
body: <p>I am trying to use Mongo's GeoSpatial features to locate documents based on coordinates. 
  I need to create indexes for it to work - but it seems like I can't get the index created? Can you help?</p>
  
  <p>I'll walk through what I have so far.</p>
  
  <pre><code>//User saves the location using a PUT Command. 
  props.updateBandLocation({
          geometry: { 
              type: "Point", 
              coordinates: [ lat, lon ] 
          }
      })
  </code></pre>
  
  <p>Here is the route that puts it in the database. I try to get the index created here. </p>
  
  <pre><code>router.put('/:id',    (req, res) =&gt; {
  quoteGenerator.findByIdAndUpdate({_id: req.params.id}, req.body).then(() =&gt; {
      quoteGenerator.findOne({_id: req.params.id}).then(generator =&gt; res.send(generator))
      quoteGenerator.createIndex( { bandLocation: "2dsphere" } )
  })
  </code></pre>
  
  <p>})</p>
  
  <p>The indexing throws an error in my terminal but it creates the location anyways. Here it is in the database. </p>
  
  <pre><code>//How the query looks in the database
      "bandLocation": {
      "geometry": {
          "type": "Point",
          "coordinates": [
              32.96179,
              -96.82916850000001
          ]
      }
  },
  </code></pre>
  
  <p>Lastly, I am trying to get all the documents near a point using this route.</p>
  
  <pre><code>router.get('/allbands/:lat/:lng',   (req, res) =&gt; {
  quoteGenerator.find(
      {
      bandLocation: 
          {   $near: {
                  $geometry: {
                      type : "Point",
                      coordinates : [-req.params.lng, +req.params.lat],
                  }
              }
          }
      }
  
    ).then(bands =&gt; res.json(bands))
  </code></pre>
  
  <p>});</p>
  
  <p>Thanks for any help you have to offer!</p>
  
  <p>Here is my schema -- </p>
  
  <pre><code>    //Create GeoSchema 
  
  const GeoSchema = new Schema({
      geometry: {
          type: {
              type: String,
              default: "Point",
              index: "2dsphere",
  
          },
          coordinates: {
              type: [Number],
          },
      } 
  })
  
  //Create Schema - Band
  const AutoQuoteGeneratorSchema = new Schema({
      baseCost: {
          type: Number
      },
      mainDate: {
          type: Object
      },
      quoteGenerator: {
          type: Array,
          required: true,
      },
      userId: {
          type: String,
          required: true,
      },
      type: {
          type: String,
          required: true,
      },
      bandName: {
          type: String,
          required: true,
      },
      bandBio: {
          type: String,
          required: true,
      },
      bandLocation: GeoSchema,
      bandTour: {
          type: Array,
          required: true,
      },
      bandGenre: {
          type: String,
          required: true,
      },
      youtube: {
          type: Array,
          required: true,
      },
      published: {
          type: Boolean,
          required: true,
      },
      posts: {
          type: Array,
          required: true,
      },
  });
  </code></pre>