2

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

2
  • 1
    Can you check this answer, I think this might help you. Commented Jul 27, 2021 at 7:50
  • 1
    Was your issue resolved? Commented Jul 30, 2021 at 12:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.