Changing data

There are two types of data changes that can happen:

  • Destructive update: We override what is there
  • Non-destructive update: We merge the incoming data with what is already there

The method used for the destructive update is called set() and is used in the following way:

this.angularFireDatabase.object('/book').set({ title : 'Moby Dick' })

Given that our previous data was the following:

{
title: 'The grapes of wrath',
description: 'bla bla'
}

It has now become:

{
title: 'Moby Dick'
}

This is exactly what we mean by a destructive update: we get the title property overridden, but we also lose the description property as the entire object is being replaced. 

If the destruction of the data was not what you had in mind, then there is a softer update you can use, which is the update() method. Using it is as easy as writing the following:

this.angularFireDatabase.object('/book').update({ publishingYear : 1931 })

Given that the data looked like the following before the update() operation:

{
title: 'Grapes of wrath',
description: 'Tom Joad and his family are forced from the farm'
}

It now looks like this:

{
title : 'Grapes of wrath',
description : 'Tom Joad and his family are forced from the farm...',
publishingYear : 1931
}

Remember to select the appropriate update operation depending on your intention as it makes a difference.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset