title: Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string
body: <p>I spend too much time on trying to figure out on how FCM works so I'm looking for some wisdom. I'm trying to add push notifications for my app using Firebase Cloud messaging (FCM). I read the docs but I'm don't fully understand how it works. My app is written in Java and for the messaging I want to use javascript. In my app I have a chat rooms where users can communicate. I want to set a push notification once he gets a new message. In order to get to the chat room, the path in the database:</p>
  <pre><code>groups (collection) -&gt; &lt;group name&gt; (document) -&gt; chatRooms (collection) -&gt; &lt;chat ID&gt; (document) -&gt; roomMessages (collection) -&gt; &lt;message ID&gt; (document)
  </code></pre>
  <p>Each document in the <code>chatRooms</code> collection contains the following fields:</p>
  <ol>
  <li><code>name</code> - name of the room.</li>
  <li><code>lastMeesage</code> - The last message that was sent in the chat room (updated once the message is sent).</li>
  <li><code>lastMessageTimestamp</code> - The timestamp of the last message.</li>
  <li><code>users</code> - Array of users (paths) that are talking in the chat room.</li>
  </ol>
  <p>Each document in the <code>roomMessages</code> collection contains the following fields:</p>
  <ol>
  <li><code>message</code> - The message that was sent.</li>
  <li><code>userName</code> - The user name.</li>
  <li><code>userPath</code> - The path to the user document in the firebase.</li>
  <li><code>timestamp</code> - The timestamp of the message.</li>
  </ol>
  <p>I was following this <a href="https://firebase.google.com/docs/functions/get-started" rel="nofollow noreferrer">tutorial</a> on how to do it. I wrote the following code:</p>
  <pre><code>const functions = require('firebase-functions');
  const admin     = require('firebase-admin');
  
  admin.initializeApp();
  const db = functions.firestore;
  
  exports.onMessageSent = db.document(`groups/{groupName}/chatRooms/{chatId}/roomMessages/{messageId}`).onCreate((messageDoc, context) =&gt; {
      const message = messageDoc.message;
      const senderName = messageDoc.senderName;
      const senderPath = messageDoc.senderPath;
      const chatId = context.params.chatId;
      const groupName = context.params.groupName;
      const groupPath = 'groups/' + groupName;
  
      return admin.firestore().doc(senderPath).get().then(senderDoc =&gt; {
          var senderPhoto = null;
          if (typeof senderDoc.data().image !== 'undefined') {
              senderPhoto = senderDoc.data().image;
          }
          return admin.firestore().doc(`groups/${groupName}/chatRooms/${chatId}`).get().then(chatRoomDoc =&gt; {
              return chatRoomDoc.data().users.forEach((userPath, index) =&gt; {
                  return admin.firestore().doc(userPath).get().then(receiverDoc =&gt; {
                      console.log('Creating a chat notification for: ', receiverDoc.data().full_name);
  
                      let tokens = receiverDoc.data().tokens;
                      const payload = {
                          data: {
                              display_status: &quot;admin_broadcast&quot;,
                              notification_type: &quot;CHAT&quot;,
                              title: &quot;New message from &quot; + senderName,
                              body: message,
                              group_path: groupPath,
                              sender_path: senderPath,
                              sender_photo_url: senderPhoto,
                              chat_id: chatId
                          }
                      };
  
                      console.log(&quot;Sending notification&quot;);
                      return admin.messaging().sendToDevice(tokens, payload);
                  });
              });
          });
      });
  });
  </code></pre>
  <p>Then I ran (It does not let me run locally because - <code>function ignored because the firestore emulator does not exist or is not running.</code>):</p>
  <pre><code>firebase deploy --only functions
  </code></pre>
  <p>In android I implemented the following class:</p>
  <pre><code>public class MessagingService extends FirebaseMessagingService {
  
      @Override
      public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
          Log.d(TAG, &quot;onMessageReceived: started&quot;);
          Log.d(TAG, &quot;onMessageReceived: message is: &quot; + remoteMessage.getData());
          // code
      }
  
      @Override
      public void onNewToken(@NonNull String token) {
          Log.d(TAG, &quot;Refreshed user token: &quot; + token);
          sendRegistrationToServer(token);
      }
  
      // code
  }
  </code></pre>
  <p>But in the log section of the functions tab of the firebase console I get the following error:</p>
  <pre><code>onMessageSent
  Error: Value for argument &quot;documentPath&quot; is not a valid resource path. Path must be a non-empty string.
      at Object.validateResourcePath (/srv/node_modules/@google-cloud/firestore/build/src/path.js:406:15)
      at Firestore.doc (/srv/node_modules/@google-cloud/firestore/build/src/index.js:427:16)
      at exports.onMessageSent.db.document.onCreate (/srv/index.js:19:30)
      at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:132:23)
      at /worker/worker.js:825:24
      at &lt;anonymous&gt;
      at process._tickDomainCallback (internal/process/next_tick.js:229:7) 
  </code></pre>
  <p>What does it mean and how to fix it?</p>