I'm trying to remove all content from my Mongoose database but nothing seems to work.
I have tried
# CoffeeScript
MyModel.find().remove((err) -> console.log('purge callback'))
# JavaScript
MyModel.find().remove(function() { console.log('purge callback') })
And
# CoffeeScript
MyModel.find().remove({}, (err) -> console.log('purge callback'))
# JavaScript
MyModel.find().remove({}, function() { console.log('purge callback') })
Even removing the .find()
step or adding a .exec()
my callback never shows and my data are still here.
I am pretty sure that my model and connection are ok:
- I can see the connections in Mongo's log
- I can add documents by manipulating the same model elsewhere
Related: How do I remove documents using Node.js Mongoose?
EDIT
My problem was caused by a syntax mistake that wasn't displayed. The selected answer does work and so does the above code. Moderators are welcome to remove my question if it seems necessary.