title: Firestore triggers for Firebase Cloud Functions not working
body: <p><strong>Goal</strong>
  My goal is to print the output of any created/updated/deleted documents in Cloud Firestore using Cloud Functions</p>
  <p><strong>Setup</strong>
  I'm currently using the Firebase emulator for testing purposes. The Admin SDK is able to successfully connect to the Firestore database, but triggers won't be called. Here is my firebase.json for my project:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;firestore&quot;: {
      &quot;rules&quot;: &quot;firestore.rules&quot;,
      &quot;indexes&quot;: &quot;firestore.indexes.json&quot;
    },
    &quot;emulators&quot;: {
      &quot;auth&quot;: {
        &quot;port&quot;: 9099,
        &quot;host&quot;: &quot;127.0.0.1&quot;
      },
      &quot;firestore&quot;: {
        &quot;port&quot;: 8080,
        &quot;host&quot;: &quot;127.0.0.1&quot;
      },
      &quot;ui&quot;: {
        &quot;enabled&quot;: true
      }
    },
    &quot;functions&quot;: {
      &quot;source&quot;: &quot;functions&quot;,
      &quot;predeploy&quot;: [
        &quot;npm --prefix \&quot;$RESOURCE_DIR\&quot; run lint&quot;
      ]
    }
  }
  </code></pre>
  <p>All triggers are being loaded according to the—</p>
  <p><strong>Logs</strong> which reveal the following setup:</p>
  <pre><code>Emulator UI logging to ui-debug.log
  auth function initialized.
  auth function initialized.
  firestore function initialized.
  
  ┌─────────────────────────────────────────────────────────────┐
  │ ✔  All emulators ready! It is now safe to connect your app. │
  │ i  View Emulator UI at http://localhost:4000                │
  └─────────────────────────────────────────────────────────────┘
  
  ┌────────────────┬────────────────┬─────────────────────────────────┐
  │ Emulator       │ Host:Port      │ View in Emulator UI             │
  ├────────────────┼────────────────┼─────────────────────────────────┤
  │ Authentication │ 127.0.0.1:9099 │ http://localhost:4000/auth      │
  ├────────────────┼────────────────┼─────────────────────────────────┤
  │ Functions      │ localhost:5001 │ http://localhost:4000/functions │
  ├────────────────┼────────────────┼─────────────────────────────────┤
  │ Firestore      │ 127.0.0.1:8080 │ http://localhost:4000/firestore │
  └────────────────┴────────────────┴─────────────────────────────────┘
    Emulator Hub running at localhost:4400
    Other reserved ports: 4500
  </code></pre>
  <ul>
  <li>Firestore and Auth emulators are on 127.0.0.1 because setting it to the default &quot;localhost&quot; caused it to fail.</li>
  </ul>
  <p><strong>index.js</strong></p>
  <pre class="lang-js prettyprint-override"><code>const functions = require(&quot;firebase-functions&quot;);
  const admin = require(&quot;firebase-admin&quot;);
  admin.initializeApp();
  
  exports.newDoc = functions.firestore
    .document(&quot;/{collection}/{docID}&quot;)
    .onCreate((snapshot, context) =&gt; {
      console.log(snapshot.data());
    });
  </code></pre>
  <p><strong>What I've tried</strong>
  When any new records are added, even if the Admin SDK has added them, the documents are not read.</p>
  <ul>
  <li>I've reset all security rules as they restricted read/write access.</li>
  <li>I've tried the production environment instead of the emulator. I didn't expect this to work as the functions aren't deployed</li>
  </ul>