2

I need to update objects in my database, so I do this:

const items = af.database.list('/items');
items.update('key-of-some-data1', { size: newSize1 });
items.update('key-of-some-data2', { size: newSize2 });

This works like a charm, but I would like to update items with a "data fan-out" as described here: https://firebase.google.com/docs/database/web/read-and-write https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html

So I do:

var updates = {};
updates['key-od-some-data1']= { size: newSize1 };
updates['key-od-some-data2']= { size: newSize2 };
items.update(updates);

Unfortunately I get this error:

zone.js:140 Uncaught Error: Error in ./AppComponent class AppComponent - inline template:30:2 caused by: Method requires a key, snapshot, reference, or unwrapped snapshot. Got: object

Is it even possible to update with data fan-out to the database with angularfire2? Does data fan-out work only with the same object key or something?

3
  • do you have an example of how to get the key using AF2? I'm trying to do the same thing, but I'm running into a TS error when calling child('/path').push().key(); Commented Nov 6, 2016 at 20:21
  • Do you mean 'key' you just created? It's genereated automatically. Try key=child('/path').push();https://firebase.google.com/docs/database/web/read-and-write Commented Nov 6, 2016 at 20:44
  • I just got it by doing items.push('new item').then(res => console.log(res.key)); thanks, anyway Commented Nov 6, 2016 at 20:46

1 Answer 1

4

Replace:

const items = af.database.list('/items');

with:

const items = af.database.object('/items');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.