title: Connect my application (node, express, mongo) with my local database and query it
body: <p>I build a small application with node.js, express.js, passport.js and mongodb. I'm new to this technology so I'm trying to test it locally before uploading the code on a server and connect it with mongolab. Now my problem is that I'm not able to see or query all my user locally with my mongo shell, so, everytime I add a user, I'm not able to see if I really add it or not. So far my code is the following:</p>
  
  <p>app.js</p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  
  var port = process.env.PORT || 3000;
  
  var passport = require('passport');
  var LocalStrategy = require('passport-local').Strategy;
  
  var mongoose = require('mongoose');
  var flash = require('connect-flash');
  var session = require('express-session');
  
  var routes = require('./routes/index');
  var users = require('./routes/users');
  
  var configDB = require('./config/database.js');
  mongoose.connect(configDB.url);
  </code></pre>
  
  <p>database.js (config/database.js)</p>
  
  <pre><code>module.exports = {
    url: 'mongodb://localhost/expressauth',
  };
  </code></pre>
  
  <p>user.js (models/user.js)</p>
  
  <pre><code>var mongoose = require('mongoose');
  var bcrypt   = require('bcrypt-nodejs');
  
  var userSchema = mongoose.Schema({
    local: {
      name: String,
      email: String,
      password: String,
    },
  });
  
  userSchema.methods.generateHash = function(password) {
    return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
  };
  
  userSchema.methods.validPassword = function(password) {
    return bcrypt.compareSync(password, this.local.password);
  };
  
  module.exports = mongoose.model('User', userSchema);
  </code></pre>
  
  <p>The code is working fine so far, and every time I add a new user I'm able to obtain a user id (something like that 59397add4905d20f0329125c) and a password.</p>
  
  <p>Now I'm trying to see all my users through the mongo shell so I type MONGO in my terminal and then I type SHOW DBS, so I can see all my database.</p>
  
  <p>I can find the database that I create through my database.js (url: 'mongodb://localhost/expressauth') called expressauth, so I switch to it (USE expressauth) and at the very end I try to make a query (something like SELECT * in mysql) with this method that I found in the documentation => db.expressauth.find().</p>
  
  <p>But I don't receive any data. So I'm not able to test my application (which is actually an web app that I found on github: <a href="https://github.com/danielgynn/express-authentication/" rel="nofollow noreferrer">https://github.com/danielgynn/express-authentication/</a>.</p>
  
  <p>Any suggestion why my mongoshell is not working?</p>