Closed saamerm closed 2 years ago
Came here cause started using this a few hours ago and noticed the exact same thing, and was wondering if there was any downside (other than it being a Put request) in using Update to "Upsert" records, as I need my keys to match too lol
No downside. PutAsync just acts as an upsert (like you said), and is the way to achieve custom keys when using this particular library.
Cool - thanks for clarifying - perfect for what I need :)
For the original poster, so you don't have to just take my word for it, here's a short excerpt from the docs:
Since each user will have a unique username, it makes sense to use PUT here instead of POST since we already have the key and don't need to create one.
Post is designed to create a new child node with a generated ID under the current path. Put doesn't create a new child node; it just operates on the current path.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing the issue due to inactivity. Feel free to re-open
Thank you for this awesome package!
I have been raking my brain for weeks trying to figure out how to set a custom key when pushing new data to the firebase real time database.
I was trying to do this to push the data, while hoping to use the UID as the key:
However, as you notice, it was adding another child with ID inside my UID:
I tried to search far and wide but the API's in the Google Firebase docs for Real time database are different than this package and several functions meant to do this aren't available. Close to giving up I decided to try PutAsync instead of PushAsync like this:
Miraculously it seems to have fixed the issue of the extra child, but I have no clue why. I also checked the docs and the source code to see what's going on but I have no clue.
Does any one have an explanation for this behavior? And is it possible use PostAsync instead of PutAsync since Put is supposed to be meant for updating and not creating a new item?