1

I'd like to set a document to my firstore. This document looks as following:

export interface ICountry {
  key: string;
  translations: Map<string,string>;
}

Such that for example the country 'France' would have as translations

translations.get('fr') === 'France'; // French
translations.get('nl') === 'Frankrijk'; // Dutch
translations.get('de') === 'Frankreich'; // German

But if i now want to upload that document to my firestore,

public async setCountry(country: ICountry): Promise<void> {
  return this.firestore
  .collection(this.collectionPath)
  .doc(country.key).set(country);
}

then I get the following error

Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: Function DocumentReference.set() called with invalid data. Unsupported field value: a custom Map object (found in field translations in document countries/france)

It seems that Firestore is unable to save this Map format. So I wonder now

  1. Is there a better data structure to save my translations in?
  2. If not, to what do I need to convert my Map<string,string> to and how in order to be able to save it.

I'd like the final document to look like this enter image description here

Wouter Vandenputte
  • 1,948
  • 4
  • 26
  • 50

0 Answers0