title: How to use cloud function trigger based on two collections documents
body: <p>I have a collection ReferalCodes in which each document is specified has these values where 'mine' value is false 'msg' value is false and mycode is user referal codes.</p>
  <pre><code>  appliedcode: &quot;&quot;
    mine:false
    msg:false
    mycode:&quot;ASDF4G&quot;
    referals : []
  </code></pre>
  <p>And User has one more collection UserTransaction which have a field 'CountTrans' which is initialized as 0 when this value is 1 i want to trigger a function to check value of mine and appliedcode if the value of mine is true then and applied code have value of length 6 then i want to update the UserTransaction of that user and the appliedcode is referal code of some another user want to change UserTransaction of that user also</p>
  <pre><code>      const functions = require('firebase-functions');
    const admin = require('firebase-admin');
  
  
    const { user } = require('firebase-functions/lib/providers/auth');
   admin.initializeApp();
  
  const db = admin.firestore();
  
  exports.getCount= functions.firestore
  .document('UserTransactions/{id}')
  .onUpdate((change, context) =&gt; { 
  const newTransdata = change.after.data();
  const previousTransData = change.before.data();
  const docid = context.params.docid;
  
  
  if(newTransdata.CountTrans === 1) {
      const referalData = await 
  admin.firestore.collection('ReferalCodes').doc(docid).get()
      const mine = referalData.mine;
      const appliedCode = referalData.appliedCode;
      let codes = [];
      var myfrindid;
      if(mine === true &amp;&amp; appliedCode !== null) {
          const friendData = await 
  admin.firestore.collection('ReferalCodes').doc('codes').get();
          var referalcodes = friendData['ReferalCodes'];
          referalcodes.forEach((items) =&gt;{
              if (items['code'] == appliedCode) {
                myfrindid = items['id'];
              }
            });
          await 
  admin.firestore.collection('ReferalCodes').doc(docid).update({
              msg: true
          })
      
      }else{
  
      }
  }
  });
  </code></pre>