title: Separate database for each user using mongodb and mongoose
body: <p>I am using mongodb and mongoose to handle my database needs. I currently have this:</p>
  
  <pre><code>mongoose.connect(secrets.db, {server:{poolSize: 1}});
  mongoose.connection.on('error', function() {
    console.error('MongoDB Connection Error. Make sure MongoDB is running.');
  });
  </code></pre>
  
  <p>As my mongo connection. I want to change that so that each user that logs in (using passport) gets their own database. So when I do <code>show dbs</code> I would like to see <code>user_ObjectID_database_name</code> how can I modify my code to get this result? I want it because I believe it is more secure from my research. I can not however find any good guides on how to do this. I am sure they exist but I have spent 4 ish hours looking with no luck on even a semi-okay one that I could guess at. </p>
  
  <p>Currents I just have a <code>users</code> collection. </p>
  
  <p>This is my current code that runs when a user hit <code>/signup</code> as a <code>POST</code> request. </p>
  
  <pre><code>exports.postSignup = function(req, res, next){
    req.assert('email', 'Please sign up with a valid email.').isEmail();
    req.assert('password', 'Password must be at least 6 characters long').len(6);
  
    var errors = req.validationErrors();
  
    if (errors) {
      req.flash('errors', errors);
      req.flash('form', {
        email: req.body.email
      });
      return res.redirect('/signup');
    }
    // calls next middleware to authenticate with passport
    passport.authenticate('signup', {
      successRedirect: '/dashboard', // Select redirect for post signup
      failureRedirect: '/signup',
      failureFlash : true
    })(req, res, next);
      next();
  };
  </code></pre>
  
  <p>I call this as a middleware in my route to keep them cleaner. </p>
  
  <p>EDIT **</p>
  
  <p>Would sharding be a better solution for performance? I know it requires a lot of set up and planning but it might be worth it? Only question is security...</p>