Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda