Back

How to restrict user to create only certain number of document in a collection

  • 0
  • Users
  • Flutter
  • Tools
  • Accounts
new user
30 Apr, 2023, 20:18

How we can restrict user to upload only certain number of document in a collection

TL;DR
The user wants to restrict the number of documents a user can create in a collection. One solution is to use a function that validates and creates the document if the validation passes. This can be done using the Appwrite Functions feature. The user can query the list of documents using the list documents API to count the number of existing documents in the collection. By forcing users to execute a function instead of using the create document API, validation can be done before creating the document.
Drake
30 Apr, 2023, 20:20

Same as any other validation: use an Appwrite Function to do validation before creating/updating

new user
30 Apr, 2023, 20:22

is there is any other option?

new user
30 Apr, 2023, 20:26

except this

Drake
30 Apr, 2023, 20:30

Nope. Functions are the way to go for any sort of custom behavior

new user
30 Apr, 2023, 20:31

example if you can provide, for how to restrict via function

Drake
30 Apr, 2023, 20:34

The idea is instead of using the create document API, you would force users to execute a function. The function can do validation and only create the document if validation passes

new user
30 Apr, 2023, 20:36

yes you are right, but how do i know that how many documents is created previously or how will i count the document

Drake
30 Apr, 2023, 20:49

You'll need a way to query for it using the list documents API

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more