Reputation: 1627
I am populating my db (--modulus.io) everytime I run the server, in my model, since that gets called. However, I am unable to remove the contents of the table right before I populate, so I get duplicate contents.
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, Collection = mongoose.Collection;
var taskSchema = mongoose.Schema({
....
});
mongoose.model('Task', taskSchema).remove();
module.exports = mongoose.model('Task', taskSchema);
The remove() method seems to not get called. Any pointers as to why this would happen?
Upvotes: 0
Views: 33
Reputation: 12985
I prefer to remove document like
model.remove({}).exec();
Or by using callback
model.remove( function (err) {
if (err) throw err;
// Removed
});
Refer documentation
Upvotes: 1