Answer the question
In order to leave comments, you need to log in
How to add value to Map (hash array) in Firestore (Firebase)?
How to add a new "key:value" entry to a field of type Map?
At the same time:
1) without deleting those records that are already there
2) the value is a reference to another record
I use the hash to guarantee the uniqueness of the records.
Of course, you can completely recreate it every time - read the contents, add it and save it in its entirety. But it is assumed that there will be many entries, and each time I would not want to overwrite the entire "array".
PS.
Couldn't figure it out from what I found online. There are different instructions on how to work with simple arrays - there are special functions arrayUnion and arrayRemoveto add and remove only one value. But this is not suitable for Map - Firebase creates an array element. I need hash.
Answer the question
In order to leave comments, you need to log in
I had only to ask a question, how I myself found the answer through experiments :)
I’ll leave it for the future:
const listRef = firebase.firestore().collection('/users').doc(userId).collection('lists').doc(listId)
const wordRef = firebase.firestore().doc(wordPath)
listRef.update({
[`words.${word}`]: wordRef
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question