PaulM PaulM - 5 months ago 33
Node.js Question

nodejs/mongodb, remove entire collection

I'm trying to remove all items in a collection.

db.collection('sessions', function(err, collection) {

This is the error I get:

throw e; // process.nextTick error, or 'error' event on first tick
TypeError: Cannot call method 'getRequestId' of null
at [object Object].executeCommand (/srv/www/
at Collection.remove (/srv/www/
at /srv/www/
at [object Object].collection (/srv/www/
at new <anonymous> (/srv/www/
at Object.<anonymous> (/srv/www/
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)

However, I can do this via mongodb fine:


What's the best way to achieve what I want via node?



Going back to this... just to update the question.

store.collection('sessions',function(err, collection){
    collection.remove({},function(err, removed){