Search code examples
node.jspostman-collection-runnerrest

delete all in rest.api?


How to delete all JSON in MongoDB collections using rest API?

router.delete('/:id', async(req, res)=> {

    const delbyid = await persons.deleteOne();
        res.status(200).json(delbyid);

})


Solution

  • The deleteOne and deleteMany methods exist in the Collection class and are used to remove documents from MongoDB.

    Use persons.deleteMany({});

    Ref. db.collection.deleteMany() CRUD Operations