2

I want to remove dirty data in the database (the database & the collections) , However the following code is not work ? How could I drop database with mongoose ?

console.log(uri) // uri = mongodb://localhost/dev 

var db = mongoose.connect(uri,function(err){
  if (err) console.log(err) // no err output
});

mongoose.connection.on('open', function(){ //db.connection is not work too .
  mongoose.connection.db.dropDatabase(function(err){
  console.log(err); // no err output 
  });
});

All my data and database are still not deleted .

Stennie
  • 63,885
  • 14
  • 149
  • 175
elrrrrrrr
  • 894
  • 8
  • 15
  • I initially closed this as a duplicate of http://stackoverflow.com/questions/10081452/drop-database-with-mongoose but it looks like you're already using that approach so I reopened it. What do you mean by "db.connection is not work too"? – JohnnyHK Aug 23 '14 at 13:14
  • var db = mongoose.connect(uri,function(err){ if (err) console.log(err) // no err output }); db.connection.on('open', function(){ //db.connection is not work too . mongoose.connection.db.dropDatabase(function(err){ console.log(err); // no err output }); }); – elrrrrrrr Aug 24 '14 at 09:30
  • No version of Mongoose was provided, but this question is over 2 years old, so it has likely expired. – Mark Stosberg Mar 17 '17 at 14:22

0 Answers0