Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

How can we delete all documents from a collection using the Payload API?

default discord avatar
Above The Cloudslast year
3

What is the best way to delete all documents in a collection using the Payload API?



Using Mongoose we can simply use deleteMany() - but the Payload API is "forcing" the definition of a 'where' clause - which can't be empty otherwise no document is deleted:



await payload.delete({ collection: "users", where: { } });



Thanks in advance!



How can we delete all documents from a collection using the Payload API?

  • default discord avatar
    jarrod69420last year

    Could you say: where: { id: { exists: true } }

  • default discord avatar
    Above The Cloudslast year

    As simple as that! I am used to use '$exists' and didn't think of 'exist' - thanks lot!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team..