title: Cloud function -> comparing timestamps
body: <p>I'm trying to make a cloud function where the function deletes every item in the "links" collection where the "eindTijd" (endtime) timestamp is older than now.</p>
  
  <p>The function executes on every DB write, and gives me no errors at all, but just doesn't do what I intend to do. It's driving me nuts!</p>
  
  <p>I suspect the error is in the oldItemsQuery, but cannot find out what goes wrong. Any help would be really appreciated!</p>
  
  <p>The "eindTijd" field is generated with a Date function and is recognized to be a valid timestamp in Firestore. </p>
  
  <pre><code>  'use strict';
  
  const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp();
  
  const firestore = admin.firestore();
  const settings = {timestampsInSnapshots: true};
  firestore.settings(settings);
  
  exports.verwijderOudeNodes = functions.firestore
  .document('/links/{pushId}')
  .onWrite(() =&gt; {
    const now = Date.now();
    let oldItemsQuery = firestore.collection('links').where('eindTijd', '&lt;=', now);
    return oldItemsQuery.get().then((snapshot) =&gt; {
      // create a map with all children that need to be removed
      let batch = firestore.batch();
      snapshot.forEach(child =&gt; {
        batch.delete(child.ref);
      });
      // execute all updates in one go and return the result to end the function
      return batch.commit();
    });
  });
  </code></pre>