Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I know how to...

  • Remove a single document.

  • Remove the collection itself.

  • Remove all documents from the collection with Mongo.

But I don't know how to remove all documents from the collection with Mongoose. I want to do this when the user clicks a button. I assume that I need to send an AJAX request to some endpoint and have the endpoint do the removal, but I don't know how to handle the removal at the endpoint.

In my example, I have a Datetime collection, and I want to remove all of the documents when the user clicks a button.

api/datetime/index.js

'use strict'; 

var express = require('express'); 

var controller = require('./datetime.controller'); 

var router = express.Router(); 

router.get('/', controller.index); 

router.get('/:id', controller.show); 

router.post('/', controller.create); 

router.put('/:id', controller.update); 

router.patch('/:id', controller.update); 

router.delete('/:id', controller.destroy); 

module.exports = router;

1 Answer

+1 vote
by (106k points)

You should use DateTime.remove({}, callback) The empty object will match all of them.

Related questions

0 votes
2 answers
0 votes
2 answers
0 votes
2 answers
0 votes
2 answers

Browse Categories

...