Reputation: 7
I have a firebase map object and i need to insert arrays inside
I am trying to use update function but it doesn't work
dialogRef.afterClosed().subscribe(result => {
console.log(result);
const arrayname = result.name;
const fireupdate = this.af.list('/users/' + this.Uid + '/items').update(arrayname, result);
});
this is how the result array looks like
{name: "item", price: 25, desc: "a simple item"}
I don't get anything in the firebase
Upvotes: 0
Views: 9187
Reputation: 3740
So what is easiest to do is add the array to the doc as shown in the other answer.
this.db.collection("users").doc(this.Uid).update({items: [{name: "item", price: 25, desc: "a simple item"}, {name: "item2", price: 20, desc: "a simple item2"}]})
What you must be careful about is that firestore not really have a good way to query an array with objects yet:
What Firestore want you to do is basicly:
this.db.collection("users").doc(this.Uid).collection('items').add({name: "item", price: 25, desc: "a simple item"})
Upvotes: 4
Reputation: 83103
If I am not mistaking, by doing this.af.list('/users/' + this.Uid + '/items').update()
you are actually trying to write to the Realtime Database, see https://github.com/angular/angularfire2/blob/master/docs/rtdb/lists.md#updating-items-in-the-list-using-update
But the database that you show in your question is Firestore, the other database service offered by Firebase.
You should use the part of the angularfire2 library dedicated to Firestore, see https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md#using-angularfirestoredocument
Upvotes: 0