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, enableignoreUndefinedProperties.
The city data in this case is undefined, but I want to ignore undefined data.
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
}