Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
How can I ignore undefined values when updating Firestore data from a Google Cloud Function?

In my index.js file, I have:

const db = admin.firestore();
db.settings({ignoreUndefinedProperties:true});

In my other .js file with the actual function, I have:

const functions = require('firebase-functions');
const {Client, ReverseGeocodingLocationType, AddressType} = require("@googlemaps/google-maps-services-js");

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
}

However, I am still getting this error:

Value for argument "data" is not a valid Firestore document. Cannot use "undefined" as a Firestore value (found in field "location.city"). If you want to ignore undefined values, enable ignoreUndefinedProperties.

The city data in this case is undefined, but I want to ignore undefined data.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

ignoreUndefinedProperties:true is not a valid SetOption

Reference for SetOptions: https://firebase.google.com/docs/reference/js/v8/firebase.firestore.SetOptions

You could pass merge: true and omit fields to leave them unchanged.

You still need a code change to not pass keys that are unchanged.

async function addLocationData(addressComponents, reference){
    cityName = getLocationType(addressComponents, 'locality')
    stateName = getLocationType(addressComponents, 'administrative_area_level_1')
    countryName = getLocationType(addressComponents, 'country')
    const data = {}
    if (cityName != null) { 
      data['city.name'] = cityName;
    }
    // etc
    await reference.set(data, {merge: true})
    return true
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda