Some ideas about new functions that can be added as an extension to the firebase functions library.
This functions is triggered when a field inside a document is added to the document for the first time. That can be if:
- The document created for the first time and includes this field.
- The document has been created before without that field, and has been updated to include it.
const functions = require("firebase-functions");
exports.myFunction = functions.firestore
.document("my-collection/{docId}")
.onWrite((change, context) => {
const isFieldCreated =
change.before.get(FIELD_NAME) === undefined &&
change.after.get(FIELD_NAME) !== undefined;
if (!isFieldCreated) return;
/* ... */
});
Note Checking the value to be a strong
undifined
asnull
,0
, and empty string are all valid Firestore document values, however undefined is not.
This function is triggered when a field inside a document already exists and has been updated.
If the document as whole is updated, whoever the field value hasn't changed this function should'nt be triggered.
This function is triggered when a field inside a document is delted from the document. This can be if:
- The document has be deleted as whole.
- The field was exists in the document and the document has been updated and it's not exists in the new version.