Monday, 10 April 2017

Mongoose - multiple collection parallel document creation

I am running into a problem when I create documents for different collections. Here the last callback attached to create(...) for each model(corresponding to a collection) is to drop the respective collection but it is not working consistently.

e.g. We have 3 models A, B and C.

db.once('open',function(){

A.create({

...

},function(err,doc){

db.collection('a').drop();

});

B.create({

...

},function(err,doc){

db.collection('b').drop();

});

C.create({

...

},function(err,doc){

db.collection('c').drop();

});

}

All the 3 collections do not get dropped every time.

What could be the reason?



via HBalyan

No comments:

Post a Comment