Reputation: 1747
I just started to create an app with Vuejs + firebase, and I am having problems to update or remove grandchildren items.
To create a grandchild I have successfully used the following:
spotsRefs.child(spot['.key']).child('pictures').push(picture)
but for removing a grandchild, it doesn't work I am trying something like this:
spotsRefs.child(spot['.key']).child('pictures').child(picture).remove()
For updating the grandchild I am not really sure how to get the autogenerated -LZJYrFFx9RMdiqMv5dv id
this is how it looks in the console:
I have 2 different functions, for create and delete:
this.$root.$on('create', (spot, picture) => {
spotsRefs.child(spot['.key']).child('pictures').push(picture);
});
this.$root.$on('delete', (spot, picture) => {
spotsRefs.child(spot['.key']).child('pictures').child(picture).remove()
});
Upvotes: 0
Views: 182
Reputation: 22403
You need to pass using child key instead of .child(picture)
Get the reference to added child:
const addedChildRef = spotsRefs.child(spot['.key']).child('pictures').push(picture)
and then remove
spotsRefs.child(spot['.key']).child('pictures').child(addedChildRef.key).remove()
or
addedChildRef.remove()
Upvotes: 1