Search code examples
pythonfirebasegoogle-cloud-firestorefirebase-admin

How to add element to array at firestore database? (python)


I need to add some value (val) to existing array in google.cloud.firestore document.

I found solution like that:

database.collection('collection_name').document('document_id').update({'array_name': firestore.ArrayUnion([val])})

where 'array_name' is name of array-type field in document with 'document_id' id in collection 'collection_name'.

That code used:

import firebase_admin
from firebase_admin import firestore

and database is:

database = firestore.client()

But PyCharm says:

Cannot find reference 'ArrayUnion' in 'firestore.py'


Solution

  • The problem was in PyCharm Indexes, something like that. Code could run and ArrayUnion worked, but IDE said that there are no function ArrayUnion.