title: how to update a value in firebase realtime database using Cloud Functions for Firebase
body: <p>I went though the firebase docs for updating a value in realtime database using Cloud Functions for Firebase, but am not able to understand.</p>
  
  <p>My database structure is</p>
  
  
  
  <pre><code>{   
   "user" : {
      "-KdD1f0ecmVXHZ3H3abZ" : {
        "email" : "ksdsd@sdsd.com",
        "first_name" : "John",
        "last_name" : "Smith",
        "isVerified" : false
      },
      "-KdG4iHEYjInv7ljBhgG" : {
        "email" : "superttest@sds213123d.com",
        "first_name" : "Max1",
        "last_name" : "Rosse13131313l",
        "isVerified" : false
      },
      "-KdGAZ8Ws6weXWo0essF" : {
        "email" : "superttest@sds213123d.com",
        "first_name" : "Max1",
        "last_name" : "Rosse13131313l",
        "isVerified" : false
      } 
  }
  </code></pre>
  
  
  
  <p>I want to update the isVerified using database trigger cloud functions. I don't know how to update a database value using cloud functions (language : Node.JS)</p>
  
  <p>I wrote a code to automatically update the value of the key 'isVerified' of a user, when the user is created by using database trigger onWrite. My code is </p>
  
  <pre class="lang-js prettyprint-override"><code>const functions = require('firebase-functions');
  
  const admin = require('firebase-admin');
  admin.initializeApp(functions.config().firebase);
  
  exports.userVerification = functions.database.ref('/users/{pushId}')
      .onWrite(event =&gt; {
      // Grab the current value of what was written to the Realtime Database.
      var eventSnapshot = event.data;
  
      if (event.data.previous.exists()) {
          return;
      }
  
      eventSnapshot.update({
          "isVerified": true
      });
  });
  </code></pre>
  
  
  
  <p>but when i deploy the code, and add a user to the database, the cloud function log shows the below error</p>
  
  <pre class="lang-js prettyprint-override"><code>TypeError: eventSnapshot.child(...).update is not a function
      at exports.userVerification.functions.database.ref.onWrite.event (/user_code/index.js:10:36)
      at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:35:20
      at process._tickDomainCallback (internal/process/next_tick.js:129:7)
  </code></pre>