You can test out this extension right away!
-
Go to your Cloud Firestore dashboard in the Firebase console.
-
Call the HTTP function passing an object with the properties described in the README. You need to specify the type of
change
you'd like to execute, thecollection
you wish to add the document to, thefieldName
you want to ensure uniqueness, and thedocument
itself. -
In a few seconds, you'll see a new collection in Firestore with a new document, that document will have as the key the value of the field of the document you sent to the function.
-
This newly created collection and documents will prevent the client creating documents with duplicate values for the specified field, since we're using transactions inside the function that check the uniqueness of the specified field.
-
You have the option to hash the field selecting 'Yes' when prompted to hash the field upon installation, due to constraints on document IDs.
-
You also have the option to require auth selecting 'Yes' when prompted to require auth upon installation, since you may want this function to be invoked only by authenticated users.
Call the function with the collection users and fieldName username, with a document with id exampleId with the string "bob1234" as the value to the field username will result in the following document written in the collection users-username:
{
bob1234: {
id: exampleId,
username: bob1234,
},
}
If you opted in to hash the field, instead of "bob1234", you'll see a hashed value as the document id.
Now, if a client-side app wants to create / update a document with the string "bob1234" to the field username in users, the function will return an error with a 'already-exists': code. For creating, updating and delting, the parameters are always change
, collection
, fieldName
and document
, the change should always be one between CREATE
, UPDATE
, and DELETE
, collection
and fieldName
should always be valid Firestore strings since they'll be used as collection and field names respectively, and the document should always contain the id as a field.
As a best practice, you can monitor the activity of your installed extension, including checks on its health, usage, and logs.