Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection returned from mongoose.connect has undefined connection.db property in 4.4.7 #3972

Closed
mleanos opened this issue Mar 12, 2016 · 3 comments
Milestone

Comments

@mleanos
Copy link
Contributor

mleanos commented Mar 12, 2016

We're connecting to our MongoDB instance with mongoose.connect. Up till the release of Mongoose 4.4.7, the returned Connection's connection.db property gave us a dropDatabase method.

After upgrading to 4.4.7, the connection.db property is undefined.

We connect this way:

var db = mongoose.connect(config.db.uri, config.db.options, function (err) {
    // Log Error
    if (err) {
      console.error(chalk.red('Could not connect to MongoDB!'));
      console.log(err);
    } else {

      // Enabling mongoose debug mode if required
      mongoose.set('debug', config.db.debug);

      // Call callback FN
      if (cb) cb(db);
    }
  });

And we have a Grunt task to drop the database:

grunt.task.registerTask('dropdb', 'drop the database', function () {
    // async mode
    var done = this.async();

    // Use mongoose configuration
    var mongoose = require('./config/lib/mongoose.js');

    mongoose.connect(function (db) {
      db.connection.db.dropDatabase(function (err) {
        if (err) {
          console.log(err);
        } else {
          console.log('Successfully dropped db: ', db.connection.db.databaseName);
        }
        db.connection.db.close(done);
      });
    });
  });

I reverted back to Mongoose 4.4.6 and this issue went away.

@mleanos
Copy link
Contributor Author

mleanos commented Mar 13, 2016

Upon further investigation, it appears the connection isn't being made. When I change the above example that connects to the database, to use createConnection instead of connect, I get the following error thrown.

gh-1264-mongoose-createconnection-error

Perhaps, I'm complicating the matter by changing the connection method to use createConnection (for the purposes of debugging) but I find it interesting that no error is thrown when attempting the connection by using connect; but it's not making the connection.

Any ideas?

@simonkontschak
Copy link

Same situation, same problem...

@vkarpov15 vkarpov15 added this to the 4.4.8 milestone Mar 17, 2016
@mleanos
Copy link
Contributor Author

mleanos commented Mar 18, 2016

@vkarpov15 My issue went away after upgrading to 4.4.8. Thanks for the prompt fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants