How to make a firebase function to use Cloud Messaging when adding an element in the firestore database

I am developing an application with Ionic.

To explain a little, it is a text book, the teachers add the homework and we see them.

The database is managed by Firestore. I’m receiving Cloud Messaging notifications on my phone.

I would like to know if it is possible with Firebase to synchronize Firestore and Cloud Messaging.

Can you provide me with a code so that as soon as a teacher adds an homework (with an ID automatically generated on Firebase), Cloud Messaging sends a notification to all users, therefore iOS and Android with a Title and a body

Thanks in advance