55
rated 0 times
[
56]
[
1]
/ answers: 1 / hits: 184512
/ 12 Years ago, fri, may 11, 2012, 12:00:00
I want to drop some mongodb collections, but that's an asynchronous task. The code will be:
var mongoose = require('mongoose');
mongoose.connect('mongo://localhost/xxx');
var conn = mongoose.connection;
['aaa','bbb','ccc'].forEach(function(name){
conn.collection(name).drop(function(err) {
console.log('dropped');
});
});
console.log('all dropped');
The console displays:
all dropped
dropped
dropped
dropped
What is the simplest way to make sure all dropped
will be printed after all collections has been dropped? Any 3rd-party can be used to simplify the code.
More From » node.js