title: How can I ignore undefined values when updating Firestore data from a Google Cloud Function?
body: <p>In my index.js file, I have:</p>
  <pre><code>const db = admin.firestore();
  db.settings({ignoreUndefinedProperties:true});
  </code></pre>
  <p>In my other .js file with the actual function, I have:</p>
  <pre><code>const functions = require('firebase-functions');
  const {Client, ReverseGeocodingLocationType, AddressType} = require(&quot;@googlemaps/google-maps-services-js&quot;);
  
  async function addLocationData(addressComponents, reference){
      cityName = getLocationType(addressComponents, 'locality')
      stateName = getLocationType(addressComponents, 'administrative_area_level_1')
      countryName = getLocationType(addressComponents, 'country')
      await reference.set({
          'location.city': cityName,
          'location.state': stateName,
          'location.country': countryName
      },{ignoreUndefinedProperties:true})
      return true
  }
  </code></pre>
  <p>However, I am still getting this error:</p>
  <blockquote>
  <p>Value for argument &quot;data&quot; is not a valid Firestore document. Cannot use &quot;undefined&quot; as a Firestore value (found in field &quot;<code>location.city</code>&quot;). If you want to ignore undefined values, enable <code>ignoreUndefinedProperties</code>.</p>
  </blockquote>
  <p>The city data in this case is undefined, but I want to ignore undefined data.</p>