kzoeps
kzoeps

Reputation: 471

Adding new values with same keys to existing document in Firestore firebase without overwriting

I am trying to add data to the Firestore database without overwriting it. The data is in the format written below and has numerous other "Question" in the same format and I want to add this to just one document.

{
    "Question": String,
    "Answer": String,
}

The same question has been asked here but it covers it in java and not in python. I have tried updating it and setting it but it has only been overwriting it.
Note that all of my Questions are elements in a list in this format:

['{\n "Question": String,\n "Answer":String \n}, ...]

What I am currently doing in my code is going through the array and performing the code below:

doc_ref = db.collection(u"Questions").document(u"ques")
doc_ref.update(questionsAnswers)

but this only leaves me with the last question added to the database.

Upvotes: 0

Views: 1082

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317760

Use the update method to change the contents of an existing document as shown in the documentation.

city_ref = db.collection(u'your-collection').document(u'your-document')
city_ref.update({u'your-field': u'your-field-value'})

I suggest also using the API documentation.

Upvotes: 1

Related Questions