Reputation: 101
How to use a variable such as users UID as the key to a map in Firestore.
I would imagine its the same principal as out of Firestore
const userID = "gfsueudiyeueuuuke7ue"
setDoc(docRef, {
userID : {
age: 11,
name: "test"
...
}
})
Ive tried (userID): ...
as well as ${userID}
:
any suggestions?
Upvotes: 0
Views: 593
Reputation: 101
I was able to accomplish this by putting brackets [] around [userID], alos using updateDoc as to not overwrite the document.
const userID = "gfsueudiyeueuuuke7ue"
updateDoc(docRef, {
[userID] : {
age: 11,
name: "test"
...
}
})
Upvotes: 1