title: Firebase firestore cloud functions showing Error: Invalid use of type "undefined" as a Firestore argument
body: <p>I have a project to add currency details into the firestore database and my project is doing with ionic 3</p>
  
  <p>Whenever I add a new document to the collection a trigger function onCreate()  will execute and update the document named 'updated'.</p>
  
  <p>But the trigger function always showing an error.</p>
  
  <pre><code>Error: Invalid use of type "undefined" as a Firestore argument.
      at Object.exports.customObjectError.val [as customObjectError] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/validate.js:164:14)
      at Function.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:808:20)
      at Function.encodeFields (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:678:36)
      at Function.fromObject (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:218:55)
      at WriteBatch.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/write-batch.js:291:39)
      at DocumentReference.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:419:8)
      at Object.&lt;anonymous&gt; (/user_code/lib/index.js:28:10)
      at next (native)
      at /user_code/lib/index.js:7:71
      at __awaiter (/user_code/lib/index.js:3:12)
  </code></pre>
  
  <p>sombody please help..</p>
  
  <p>i have spent lot of time on it.</p>
  
  <p>Here is the code : </p>
  
  <pre><code>import * as functions from 'firebase-functions';
  
  const admin = require('firebase-admin');
  admin.initializeApp();
  
  exports.createCurrency = functions.firestore
  .document('Exchange/{ExchangeId}')
  .onCreate( async (snap, context) =&gt; {
  
  const id: string = snap.data().id;
  const branchName: string = snap.data().branchName;
  const currencyName: string = snap.data().currencyName;
  const buyingRate : string = snap.data().buyingRate;
  const sellingRate : string = snap.data().sellingRate;
  
  
   const newUser= admin.
   firestore()
   .doc(`Exchange/updated`)
   .set({
     id : id,
     branchName : branchName,
     currencyName : currencyName,
     sellingRate : sellingRate,
     buyingRate :buyingRate
    });
  
   return newUser;
  
  
   });
  </code></pre>