0

The data is the database is:

Comment:
{
     uid1:"a"
     uid2:"b"
}

and I wanted to add CommentContent which is:

uid3:"c"

I am trying to read from the database, append data to the data then update the database, and below is my code:

  const OriginalContentSnap = await getDoc(doc(db, "Comment", curSnap.id));
  const OriginalContent = OriginalContentSnap.data();
  const CommentContent = {[uid] : commentDocID.id};
  CommentContent = [...OriginalContent, CommentContent];

however, everything is fine until the last line where I am getting the following error:

Uncaught (in promise) TypeError: OriginalContent is not iterable
    

any help will be greatly appreciated.

3
  • 1
    What is the document format you are retrieving from the database? Please edit the question with document format. Otherwise it would be hard to answer this question. Commented Nov 25, 2022 at 5:45
  • 1
    console.log OriginalContent to see what it is. Seems like its not an array, so you get that error Commented Nov 25, 2022 at 5:52
  • user1998844, please let me know if the answer below was helpful. Commented Dec 8, 2022 at 7:47

1 Answer 1

3

The“OriginalContentSnapdata ()”,returns an object, which you can't iterate over ,please check this helpful DocumentSnapshot document regarding the details of the Snapshot data variables and data types,on the returned object. You should make sure your resulting object has items and it must be an array. Then, change your iterator, so it generates an array based on your fetch results.

Check the below for similar examples which will be helpful:

Sign up to request clarification or add additional context in comments.

Comments

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.