0
votes

Firestore referenceI fixed most of my other issues but what I've been stuck on for today is figuring how to get a user to have multiple posts under the same uid. Each post is under the, Post:"", field and everything I tried didn't work. Any tips or solutions?

const textToSave = inputTextField.value;
docRef.collection("ask").doc(user.uid).add({
  Post: textToSave
}).then(function () {
  console.log('saved')
}).catch(function (error) {
  console.log('error');
})
1

1 Answers

0
votes

You are trying to add() a document to a document, which is not valid. Documents can only be added to collections. You could do something like:

docRef.collection("ask")
  .doc(user.uid)
  .collection("posts")
  .add({Post: textToSave})

or you could store multiple posts in an array inside the same doc, something like:

docRef.collection("ask")
  .doc(user.uid)
  .update({
    posts: firebase.firestore.FieldValue.arrayUnion({Post: textToSave})
  })