0

I am trying to update my Firestore collection with a list of strings from python.

My list:

results = ['link1','link2']

My Firestore document is 01 Collection in document is as follow:

links (map) ----> List_of_all_links (array)----> this list should have 2 strings 0:link1 1:link2

SINCE i am coding using python, I added this :

db.collection(u'myjob').document(u'01').update(results)

Error: AttributeError: 'list' object has no attribute 'items'

For now, I have the map and the array in my firestore but without strings. Any help ?

0

1 Answer 1

1

For you to update your array elements you need to use arrayUnion() to add data and arrayRemove() to remove the previous data. For example:

old_results = ['link1','link2']
new_results = ['link3','link4']

links_ref = db.collection(u'myjob').document(u'01')
# Add new data from array links
links_ref.update({u'links': firestore.ArrayUnion(new_results)})

# Remove old data from array links
links_ref.update({u'links': firestore.ArrayRemove(old_results)})
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.