Using Polymerfire, I want to add new nodes to a Firebase without overwriting data. (I call this push
or put
behavior.)
In other words. I want to start with this:
State Amy-app
|
- emails
|
+ email1@example,com
+ email2@example,com
And finish with this.
State Bmy-app
|
- emails
|
+ email1@example,com
+ email2@example,com
+ email3@example,com
+ email4@example,com
But when I start with State A and do this:
<firebase-document
id="doc"
app-name="app"
data="{{data}}">
</firebase-document>
...
this.$.doc.save('/', 'emails');
I wind up with this:
State Bmy-app
|
- emails
|
+ email3@example,com
+ email4@example,com
Notice the starting data: email1@example,com
and email2@example,com
were deleted.
Here is the Polymerfire documentation. But it doesn't mention anywhere how to accomplish this type of push
or put
-type method to insert data into a node.
How can I accomplish this?
Edit
The answer by @motss suggests:
this.$.doc('/emails');
instead of
this.$.doc('/', 'emails');
But that does not work because it adds a random auto key as follows:
State Bmy-app
|
- emails
|
- -hvOxpxwjpWHBYGj-Pzqw
|
+ email3@example,com
+ email4@example,com
Note the added key: -hvOxpxwjpWHBYGj-Pzqw
thereby destroys the indexing feature of the data structure.
As far as I know, the
save
method does things differently in two ways:set
new data into current location.push
new data into current location.In order to
push
new data, you have to submit nokey
as the second argument in thesave
method:Hope this helps IIRC. Correct me if i'm wrong.
I'm going to assume here that the emails are used as keys for objects and are not an array (since you can't have arrays in a Firebase Realtime Database). If that's the case, you probably want something like:
If you don't want to actually query the emails but just want to insert data, that's easy as well using the JS SDK:
For a third option, you can use
<firebase-document>
with a path: