How to delete all documents in a collection?

How to delete all documents in a collection?

And is this explained in the documentation somewhere?

Thanks.

1 Like

@Melody, welcome to the Fauna Community.
There are couple of ways to delete a collection.

  1. Delete the collection. More Info

  2. Read through Collection and Delete each document like shown below. Few things to be pointed.

    • Collection level Index (with no terms) exists.
    • Default Paginate size is 64. You will have to adjust the size (max: 100000) depending on the number of documents in the Collection.
    • Each Delete results in one Write Ops.
Map(
  Paginate(
    Match(Index("all_users"))
  ),
  Lambda("X", Delete(Var("X")))
)
2 Likes

I went through this just now, looking to find a one-click button to empty everything. This is just what I did:

Map(
  Paginate(
    Documents(Collection('myCollection')),
    { size: 9999 }
  ),
  Lambda(
    ['ref'],
    Delete(Var('ref'))
  )
)

No need for an index.

4 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.