1

I want to save a firebase-document to Firebase. But I encounter the following error.

error.log

Uncaught (in promise) Error: Firebase.push failed: first argument contains an invalid key ($key) in property 'xxxxxxxxxxxx.items'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

Here is the relevant code.

my-element.html
<firebase-document id="document" ... ></firebase document>
...
save: function() {
  var doc = this.$.document;
  console.log('Saved', doc.data);
  return doc.save(this.itemsPath).then(function() {
    console.log('Saved:', doc);
    doc.reset();
  }.bind(this));
  return Promise.resolve();
},

The data object contains a key label containing the $ character. But this is automatically introduced by Firebase, not a programming decision.

console.log
Saved: {
  $key: "foo" // This is the object key in Firebase
  ...
}

What edits can I make to save my data?

Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207
  • Per 43081j@[Slack site](https://polymer.slack.com/messages/general/): try pass $key as the 2nd argument, `save(path, doc.data.$key)` ... the `save(...)` method on firebase-document will call `push(...)` if a key isn't provided, otherwise it will set the value normally. but this does confuse me, you shouldn't need to call save really at all. why not just set the path? so firebase-document handles it – Let Me Tink About It Aug 09 '16 at 22:15

0 Answers0