Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: arrayunion in update document (firestore) #201

Closed
irux opened this issue Oct 3, 2018 · 7 comments
Closed

FR: arrayunion in update document (firestore) #201

irux opened this issue Oct 3, 2018 · 7 comments

Comments

@irux
Copy link

irux commented Oct 3, 2018

[READ] Step 1: Are you in the right place?

  • For issues or feature requests related to the code in this repository
    file a Github issue.
    • If this is a feature request make sure the issue title starts with "FR:".
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Windows 10
  • Firebase SDK version: ??
  • Library version: 2.13.0
  • Firebase Product: Firestore (auth, database, storage, etc)

[REQUIRED] Step 3: Describe the problem

I would like to do a array update in a collection and not replacing what it has and only join with the new value

Relevant Code:

db.collection("users").document(id).update({"myArray":["value to join"]})
@hiranya911
Copy link
Contributor

This is supported in Node.js but not in Python. It will be added in a future release.

@raytso
Copy link

raytso commented Mar 31, 2019

Any updates on this? It’s already in the tutorial docs.

@schmidt-sebastian
Copy link

CC @crwilcox

@irux
Copy link
Author

irux commented Apr 3, 2019

OK! it seems like this library doesn't support the new v1beta1 package and it imports the old firestore client. should we write a new issue for that feature ?

@busunkim96
Copy link

The library will default to v1, but you can import explicitly from v1beta1 to use this feature.

from google.cloud import firestore
from google.cloud.firestore_v1beta1 import ArrayUnion

def update_doc_array():
    db = firestore.Client()
    # [START fs_update_doc_array]
    city_ref = db.collection(u'cities').document(u'DC')

    # Atomically add a new region to the 'regions' array field.
    city_ref.update({u'regions': ArrayUnion([u'greater_virginia'])})

    # // Atomically remove a region from the 'regions' array field.
    city_ref.update({u'regions': ArrayRemove([u'east_coast'])})
    # [END fs_update_doc_array]
    city = city_ref.get()
    print(u'Updated the regions field of the DC. {}'.format(city.to_dict()))

This is from the firestore snippets.py.

@hiranya911
Copy link
Contributor

This should be supported now (at least since v3 release). Please let us know if you run into any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants