title: Cannot create a new GridStore
body: <p>I am using Gridfs to create a file and save it in mongodb. I am using console.log to figure out where the error might be. My web app allows users to create a text file and the web app will save it in mongodb. In order to save the file I am using Gridfs, however my program does not pass the line <code>var gridStores = new GridStore (db, names, "w");</code>. I can't seem to figure out why, I figured there must be something wrong with my new GridStore. Thank you for your help. </p>
  
  <p>saveFile.js:</p>
  
  <pre><code>var Files = require('C:/Users/OneDrive/workspace/Editor/Models/files.js');
  var mongoose = require('mongoose');
  var User = require('C:/Users/OneDrive/workspace/Editor/Models/users.js');
  var db = mongoose.connection.db;
  var GridStore = mongoose.mongo.GridStore;
  var Grid = mongoose.mongo.Grid;
  var SaveFile = function(names, contents){
  console.log("inside SaveFile");
  console.log("this is the name: " + names);
  console.log("this is the content: " + contents);
  var gridStores = new GridStore (db, names, "w");
  console.log("pass new gridStore ");
  gridStores.open(function(err, gridStores){
      console.log("inside open gridstor");
      gridStores.write(this.contents, function(err, gridStores){
          assert.equal(null, err);
          gridStores.close(function(err, result){
              assert.equal(null, err);
          });
      });
  });
  console.log("passed GridStore");
  findorCreateUser();
  }
  findOrCreateUser = function(){
  console.log("Inside Create user");
      User.findOne({'username' :  username },
          function(err, user) {
              if (err){
                  console.log('Error in SignUp: '+err);
                  return done(err);
              }
              if (user) {
                  user.files = gridStore;
                  user.save(function(err) {
                      if (err){
                          console.log('Error in Saving file:'+err);  
                          throw err;  
                      }
                      console.log('File Saved');    
                      return done(null, user);
                      });
                  } 
              else {
                  console.log('User already exists with username: '+username);
                  return done(null, false, req.flash('message',
                      'User Already Exists'));
              }
          });
  }
  module.exports = SaveFile;
  </code></pre>
  
  <p>Here is my user schema:</p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var bcrypt = require('bcrypt-nodejs');
  var SALT_WORK_FACTOR = 10;
  var UserSchema = new Schema({
  username:{type: String, required: true},
  password:{type: String, required: true},
      files:{type: Schema.Types.Mixed, required: false}
  }, {collection: 'Logins'});
  
  UserSchema.pre('save', function(next) {
  var user = this;
  bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
      mongoose.set('debug', true);
      if (err) 
          return next(err);
      bcrypt.hash(user.password, salt, null, function(err, hash) {
          if (err) 
              return callback(err, hash);
          user.password = hash;
          next();
      });
  
    });
  });
  module.exports = mongoose.model('Users', UserSchema);
  </code></pre>