Firebase Cloud Firestore create entry or update if it already exists

What you're looking for is the merge option in the set operation. From the documentation on setting a document:

var cityRef = db.collection('cities').doc('BJ');

var setWithMerge = cityRef.set({
    capital: true
}, { merge: true });

If you're not sure whether the document exists, pass the option to merge the new data with any existing document to avoid overwriting entire documents.