-
Notifications
You must be signed in to change notification settings - Fork 78
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
Set Firestore documents with partially merged fields - Firestore limitation #273
Comments
@ZappaUserMan The
I've opened #277 to track clarifying the client library docs for |
Please feel free to re-open / follow up if this answer doesn't work for you. |
Hi @tseaver, thank you for your reply. I am not able to re-open the issue as I am not a collaborator of this project. I already know about set with merge, but that does not help out in this case.
You can try to run that code yourself and see what the problem is. |
I am using the Python library of Firestore to communicate with Firestore.
I have now run into a limitation of Firestore and I am wondering if there is a way around it.
TL;DR / Quickly summarized with outputs: https://i.imgur.com/6WACq8Y.png
Here is a test code to try: https://trinket.io/python/abd1e75cd5
Explanation:
Imagine we have this map / Dict (dictVar1):
To begin with, I used to store my testMap in an array, but due to Firestore query limitations (you can only have a single array-contains operation in a query), I changed my structure to a map instead (as you can see in the dictVar1 structure above). If Firestore queries did not have this limitation, I would not change my structure from an array.
Now I am facing another Firestore limitation due to the new structure.
What I would like to do & other conditions:
So if the existing document would contain this data:
It would be updated to ("test0" is removed from the inner map, basically how an array would work):
And if the document doesn't exist, the document would be set to:
I see two ways to do this:
99% of the time the document exists, therefore I am fine with doing this in two operations if the document doesn't exist, but one operation if the document exists.
This could be done using Firestore's update function, but since I am using batch and potentially updating 100s of documents in one batch, if the document doesn't exist, it would ruin the whole batch operation.
Another potential solution would be to:
Two potential problems I see with this:
Do you have any ideas on how I could solve one of these problems?
The text was updated successfully, but these errors were encountered: