title: "TypeError: functions.firestore.collection is not a function"
body: <p>Looking through the Firestore documentation, I see many examples of <code>functions.firestore.document</code> but I don't see any examples of <code>functions.firestore.collection</code>. Firestore syntax is </p>
  
  <pre><code>firebase.firestore().collection('...').doc('...')
  </code></pre>
  
  <p>I get an error message with</p>
  
  <pre><code>firebase.firestore().document('...')
  </code></pre>
  
  <p>Yet in Cloud Functions with this code:</p>
  
  <pre><code>exports.myFunction = functions.firestore.collection('...').doc('...').onUpdate(event =&gt; {
  </code></pre>
  
  <p>on deploy I get an error message:</p>
  
  <pre><code>TypeError: functions.firestore.collection is not a function
  </code></pre>
  
  <p>When I change the code to</p>
  
  <pre><code>exports.getWatsonTokenFirestore = functions.firestore.document('...').onUpdate(event =&gt; {
  </code></pre>
  
  <p>I don't get an error message on deploy.</p>
  
  <p>Why does Cloud Functions appear to have a different data structure than Cloud Firestore?</p>
  
  <p>Here's my full Cloud Function. My collection is <code>User_Login_Event</code> and my document is <code>Toggle_Value</code>:</p>
  
  <pre><code>    exports.getWatsonTokenFS = functions.firestore.document('User_Login_Event/{Toggle_Value}').onUpdate(event =&gt; {
                var username = 'TDK',
                password = 'swordfish',
                url = 'https://' + username + ':' + password + '@stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api';
                request({url: url}, function (error, response, body) {
  admin.firestore().collection('IBM_Watson_Token').document('Token_Value').update('token');
                });
                return 0; // prevents an error message "Function returned undefined, expected Promise or value"
              });
  </code></pre>
  
  <p>The function deploys without error but when it executes I get this error message:</p>
  
  <pre><code>TypeError: firebase.firestore is not a function
  </code></pre>
  
  <p>I'm confused as <code>firebase.firestore</code> isn't in my Cloud Function. It's in my Angular front-end code in various places, without a problem. What is this error message referring to? I tried changing the line</p>
  
  <pre><code>admin.firestore().collection('IBM_Watson_Token').document('Token_Value').update('token');
  </code></pre>
  
  <p>to</p>
  
  <pre><code>firebase.firestore().collection('IBM_Watson_Token').document('Token_Value').update('token');
  </code></pre>
  
  <p>and to</p>
  
  <pre><code>console.log("getWatsonTokenFS response");
  </code></pre>
  
  <p>but I got the same error message.</p>