I'm trying to write a firebase cloud function to delete automatically an event after is date is passed.

Based on this example [Firebase example](https://github.com/firebase/functions-samples/blob/master/delete-old-child-nodes/functions/index.js), I came to this, but when I'm uploading it on Firebase, it is running on Firebase side but it is not deleting events. 

Do you guys have advices or see something wrong in my code ? Is it possible that the problem may coming from the trigger `onWrite()` ?

```js
/* My database structure

   /events
                item1: {
                    MyTimestamp: 1497911193083
                },
                item2: {
                    MyTimestamp: 1597911193083                    
                }
                ...
*/

// Cloud function to delete events after the date is passed

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.deleteOldItems = functions.database.ref('/events/{eventId}').onWrite((change) => {

  const ref = change.after.ref.parent; // reference to the parent
  const now = Date.now();
  const oldItemsQuery = ref.orderByChild('MyTimestamp').endAt(now);

  return oldItemsQuery.once('value').then((snapshot) => {
    // create a map with all children that need to be removed
    const updates = {};
     snapshot.forEach(child => {
        updates[child.key] = null;
     });
    return ref.update(updates);
    // execute all updates in one go and return the result to end the function
  });
});
```