title: mongoose doesn't return the output with findById
body: <p>I m learning nodejs and mongodb altogether with <a href="https://github.com/simonholmes/getting-MEAN" rel="nofollow">getting MEAN application</a> </p>
  
  <p>my system specifications are  </p>
  
  <p>ubuntu 16.04 (64 bit)<br>
   node v 6.1.0<br>
   npm v 3.8.6</p>
  
  <p>"mongodb": "^2.1.18",<br>
  "mongoose": "^4.4.16",</p>
  
  <p>So far I have created schema and add an entry in mongodb collection through terminal using <code>db.locations.save()</code> and get the generated document <strong>_id</strong> with <code>db.locations.find()</code>.</p>
  
  <p>db.locations.find().pretty() in terminal returns below output</p>
  
  <pre><code>{
      "_id" : ObjectId("57428745e89f5c55e1d057dc"),
       // and many other path 
  }
  </code></pre>
  
  <p>Now when I open <strong>/api/locations/57428745e89f5c55e1d057dc</strong> in browser, it neither gives result nor end the request. permanently show loading.. when testing with postman.</p>
  
  <p>even tried with wrong Id than it returns proper error </p>
  
  <blockquote>
    <p>{"message":"Cast to ObjectId failed for value
    \"57428745e89f5c55e1d057dca\" at path
    \"_id\"","name":"CastError","kind":"ObjectId","value":"57428745e89f5c55e1d057dca","path":"_id"}</p>
  </blockquote>
  
  <p>and with correct id </p>
  
  <pre><code>console.log(mongoose.Types.ObjectId.isValid(req.params.locationid));  // return true
  </code></pre>
  
  <p>even tried </p>
  
  <p><code>findOne({"_id": mongoose.Types.ObjectId(req.params.locationid) })</code>  </p>
  
  <p>But no results </p>
  
  <p>What could be the issue? Is there any bug in mongoose or anything missing .Below are my basic files with required code</p>
  
  <h3>loc8r/app.js</h3>
  
  <pre><code>require('./app_api/models/db');
  var routesApi = require('./app_api/routes/index');
  app.use('/api', routesApi);
  </code></pre>
  
  <h3>loc8r/app_api/models/db.js</h3>
  
  <pre><code>var mongoose  = require( 'mongoose' );    
  var mongoURI = 'mongodb://localhost/loc8r';    
  var mongoDB = mongoose.createConnection(mongoURI);
  
  mongoDB.on('connected', function (){
      console.log('mongoose connected to ' + mongoURI);
  });
  
  require('./locations');
  </code></pre>
  
  <hr>
  
  <h3>loc8r/app_api/models/locations.js</h3>
  
  <pre><code>var mongoose  = require( 'mongoose' );    
  var openingTimeSchema = new mongoose.Schema({
  days: {type: String, required: true},
  opening: String,
  closing: String,
  closed: {type: Boolean, required: true}
  });
  
  var reviewSchema = new mongoose.Schema({
  author: String,
  rating: {type: Number, required: true, min: 0, max: 5},
  reviewText: String,
  createdOn: {type: Date, "default": Date.now}
  });
  
  var locationSchema = new mongoose.Schema({
      name: {type: String, required: true},
      address: String,
      rating: {type: Number, "default": 0, min: 0, max: 5},
      facilities: [String],
      coords: {type: [Number], index: '2dspehere'},
      openingTime: [openingTimeSchema],
      reviews: [reviewSchema]
  });
  
  mongoose.model('Location', locationSchema);
  </code></pre>
  
  <h3>loc8r/app_api/router/index.js</h3>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var ctrlLocations = require('../controllers/locations');
  
  /* Locations pages */
  router.get('/locations/:locationid', ctrlLocations.locationsReadOne);
  </code></pre>
  
  <hr>
  
  <h3>loc8r/app_api/controllers/locations.js</h3>
  
  <pre><code>var mongoose = require('mongoose');
  var Loc = mongoose.model('Location');
  
  module.exports.locationsReadOne =  function (req, res) {
      if(req.params &amp;&amp; req.params.locationid) {            
          Loc
          .findById(req.params.locationid)
          .exec(function(err, location) {
              if(err) {
                  sendJsonResponse(res, 404, err);
                  return;
              }
              if (!location) {
                  sendJsonResponse(res, 404, {"message": "locationid not found"});
                  return;
              }
              sendJsonResponse(res, 200, location);
          });
      } else {
           sendJsonResponse(res, 200, {"message": "no location id in request"});
      }
  }
  
  var sendJsonResponse = function(res, status, content) {
      res.status(status);
      res.json(content);
  };
  </code></pre>