title: TypeError: Cannot read property 'name' of undefined at Firestore.snapshot_
body: <p>I am using firebase for my cloud functions in my flutter app.
  For some reason, my cloud function is not working. This is the console error:</p>
  <blockquote>
  <p>TypeError: Cannot read property 'name' of undefined at Firestore.snapshot_ (/workspace/node_modules/@google-cloud/firestore/build/src/index.js:709:128) at beforeSnapshotConstructor (/workspace/node_modules/firebase-functions/lib/providers/firestore.js:146:30) at changeConstructor (/workspace/node_modules/firebase-functions/lib/providers/firestore.js:150:49) at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:134:34)</p>
  </blockquote>
  <p>This is my cloud function code:</p>
  <pre><code>exports.onSendingNotificationsReceived3 = functions.firestore.document('/orders/{documentId}')
  
            .onCreate(async (snap, context)  =&gt; {
         // Grab the current value of what was written to Firestore
  
            snap.data()['items'].forEach((result,index) =&gt;{
            functions.logger.log('Token loop entered');
              //Getting list of shopIds from the items list in order
  
               if(listOfFCMToks.includes(result['fcmToken'])==true){
                  functions.logger.log('Token already exists');
               }else{
          listOfFCMToks.push(result['fcmToken']);
          functions.logger.log('Token of shop is added');
                    }
  
  
            });
           /* snap.data()['shipperTokens'].forEach((result,index) =&gt;{
                                          functions.logger.log('ShipperToken loop entered');
                                            //Getting list of shopIds from the items list in order
  
                                             if(listOfFCMToks.includes(result)==true){
                                                functions.logger.log('Token already exists');
                                             }else{
                                        listOfFCMToks.push(result);
                                        functions.logger.log('ShipperToken loop entered'+index);
                                                  }
  
  
                                          });*/
              functions.logger.log('3');/*
               const shopRef = admin.firestore().collection(&quot;shops&quot;);
               const querySnapshot = await shopRef.get();
               querySnapshot.forEach(async (doc) =&gt; {
                     functions.logger.log('4');
                     listOfShopIds.forEach(async (item) =&gt;{
                         if(item==doc.data()['sid']){
                          functions.logger.log('55');
                          allChecksids.push(doc.data()['sid']);
                          const tokenRef = admin.firestore().collection(&quot;users&quot;).doc(doc.data()['sid']).collection('tokens').doc('fcmToken');
                          const tokenCurrent = await tokenRef.get();
                          functions.logger.log('6');
                         functions.logger.log('88');
                           listOfUserTokensForFCM.push(doc.data()['token']);
  
  
                           listOfUserTokensForFCM.push('DataIsFound');
  
                         }
                     });
  
                     });*/
  
              functions.logger.log('66');
               await admin.messaging().sendMulticast({
          tokens : listOfFCMToks,
        notification: {
              title: &quot;A NewOrder is Placed&quot;,
            body: &quot;Please check your dashboard in Telloo App&quot;,
     imageUrl: &quot;https://firebasestorTage.googleapis.com/v0/b/learning-firebase-2d636.appspot.com/o/newOrder.jpg?alt=media&amp;token=71ad7cc8-6be6-4069-b097-75cc4f437978g&quot;,
                                                                                                     },
               }) .then((response) =&gt; {
                             console.log(
                               &quot;Notifications are sent&quot;
                             );});
              return snap.ref.set({listOfFCMToks}, {merge: true});
              });
  
  </code></pre>
  <p>Each order contains different items from multiple shop. I'm accessing fcmToken and trying to save them in a list in the same order with the cloud function use this code:</p>
  <pre><code>snap.data()['items'].forEach()
  </code></pre>
  <p>The function was working properly. But now I'm facing the error given above in the console.
  To check if this isn't the problem with the syntax of function, I created another function and tested  it:</p>
  <pre><code>exports.getOrderId = functions.firestore
                                      .document('/orders/{documentId}')
                                      .onCreate((snap, context) =&gt; {
                                        // Get an object representing the document
                                        // e.g. {'name': 'Marie', 'age': 66}
                                        const newValue = snap.data();
  
                                        // access a particular field as you would any JS property
                                        const name = newValue.orderId;
                                        functions.logger.log($name);
  
                                        // perform desired operations ...
                                      });
  </code></pre>
  <p>But upon testing this function, I'm getting the same error:</p>
  <pre><code>getOrderIdxtsp49f33azi ReferenceError: $name is not defined at exports.getOrderId.functions.firestore.document.onCreate (/workspace/index.js:147:60) at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:135:23) at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:140:25) at process._tickCallback (internal/process/next_tick.js:68:7)
  </code></pre>
  <p>What solution I found from internet:
  <strong>Soution: Change node version to 8.</strong>
  But from now we can't use functions under node 10.
  Help!</p>