Mongoose 3.1.0: Why is the callback in the connection.db.dropDatabase file (callback) never called and the DB is NOT DELETED?

the code:

var connection = mongoose.createConnection('mongodb://localhost:9000/' + databaseName);
connection.db.dropDatabase(function(err){
    // never reach this point!
    debugger;
    console.log(err);
    console.log('-------------->Dropped database: ' + databaseName);
});

If I connect to connect.open, it says that it is already opening, and multiple access to the "open" is not supported for the same connection.

Even that doesn't work

var conn = mongoose.createConnection('mongodb://localhost',databaseName, 9000, {}, function(){
    console.log('created'); // is reached
    conn.db.dropDatabase(callback); // but the callback is not called anyway
});

What is the problem? ("mongoose": "3.1.0") The database is not even discarded ... thanks

+5
source share
1 answer
    var connection = mongoose.createConnection('mongodb://localhost:9000/' + databaseName, function(err){
        connection.db.dropDatabase(function(err){
                         // now it works!
                    })
    });

The problem is that the dropDatabase command was not queued and did not start when the connection was opened. Therefore, if I used the callback for createConnection, then it worked and after that deleted the db, it works!

+3
source

All Articles