title: TypeError: Cannot read property 'find' of undefined with mongoose
body: <p>I saw a few questions like mine but couldn't find any solutions that worked so I thought I'd ask.</p>
  
  <p>I'm trying to pull all my data from my database so I can select parts of it in my app. I had my database working fine but when I tried to pull the pictures it failed and keeps giving me this error and also does not seem to receive the data from the database:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>TypeError: Cannot read property 'find' of undefined</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have mongoose installed and everything connects so I can't figure out why it won't recognize the find property. My code is below if anyone has any ideas.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Dependencies
  var express = require("express");
  var bodyParser = require("body-parser");
  var mongoose = require("mongoose");
  var exphbs = require("express-handlebars");
  var request = require("request");
  
  // var weapons = require("./weapons.js");
  
  // Set mongoose to leverage built in JavaScript ES6 Promises
  mongoose.Promise = Promise;
  
  
  // Initialize Express
  var app = express();
  
  // Use morgan and body parser with our app
  app.use(bodyParser.urlencoded({
    extended: false
  }));
  
  // Make public a static dir
  app.use(express.static(__dirname + "/public"));
  
  app.engine("handlebars", exphbs({ defaultLayout: "main" }));
  app.set("view engine", "handlebars");
  
  // Database configuration with mongoose
  mongoose.connect("mongodb://localhost/weaponsdb");
  var db = mongoose.connection;
  
  // Show any mongoose errors
  db.on("error", function(error) {
    console.log("Mongoose Error: ", error);
  });
  
  // Once logged in to the db through mongoose, log a success message
  db.once("open", function() {
    console.log("Mongoose connection successful.");
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//routes to home page
  
  app.get('/', function(req, res, next){
  
      res.render("index",{ title: 'Express' });
  
  });
  
  app.get('/app', function(req, res, next){
  
      res.render("app",{ layout: 'applayout' });
  
  });
  
  app.get("/all", function(req, res) {
  
    // Query: In our database, go to the weapon collection, then "find" everything
    db.weapon.find({}, function(error, found) {
  
      // Log any errors if the server encounters one
      if (error) {
        console.log(error);
      }
      // Otherwise, send the result of this query to the browser
      else {
        res.json(found);
      }
    });
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$.getJSON("/all", function(data) {
      console.log(data)
    // For each entry of that json...
    for (var i = 0; i &lt; data.length; i++) {
      // Append each of the weapons' properties to the table
      $("#results").append("&lt;img src = " + data[i].Picture + " /&gt;");
    }
  });</code></pre>
  </div>
  </div>
  </p>