title: How to query collections within MongoDB?
body: <p>In my database I have a collection called "users" that holds user information. I would like to add a search function that allows users to search others by username.</p>
  
  <p>My database is correctly connected in my app.js:</p>
  
  <pre><code>var mongo = require('mongodb');
  var mongoose = require('mongoose');
  
  mongoose.connect('mongodb://localhost/mobiusapp');
  var db = mongoose.connection;
  </code></pre>
  
  <p>I would like to access the "user" collection of my database to find the searched users. Here is the code I currently have to do this:</p>
  
  <pre><code>app.post('/users/search', function(req, res, next){
  
    var result = db.users.findOne();
  
    console.log(result);
  });
  </code></pre>
  
  <p>However, when I run this, I get an error: <code>TypeError: Cannot read property 'findOne' of undefined</code>.</p>
  
  <p>Is there some way to connect the collection I would like to access so that I can use it? Everything I try always ends with this error. Please help because I have no idea how to fix this. Thank you!</p>