title: I am getting this kind of error "TypeError: Cannot read property 'data' of undefined at deviceToken.then.result (/srv/index.js:14:33)" at node.js
body: <p>Here is my code:</p>
  
  <pre><code>    const deviceToken = admin.database().ref(`/users/{sender_user_id}/token_id`).once('value');
  
      return deviceToken.then(result =&gt; {
          const token_id = result.after.data();
  
          const payload = {
              notification: {
                  title: "New message!",
                  body: "You have a new message!",
                  icon: "default"
              }
          };
  
          return admin.messaging().sendToDevice(token_id, payload).then(response =&gt; {
              return console.log('This was a notification');
  
          });
      });
  
  
  });
  </code></pre>
  
  <p>And I am getting this error:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'data' of undefined
        at deviceToken.then.result (/srv/index.js:14:33)</p>
  </blockquote>
  
  <p>I am to retrieve device token id from users. How would I do that?</p>
  
  <p>node --version: v12.4.0
  npm --version: 6.9.0</p>