1

I want to avoid duplicate pushing into my firebase. The code is like this

const itemsRef = firebase.database().ref('Titles');
                console.log(itemsRef)
                let poster = this.state.data.Poster
                let title = this.state.data.Title
                let movieTitle = {
                    title: title,
                    poster : poster,
                }
                itemsRef.push(movieTitle)

This is how I'm storing my data

enter image description here

UPDATE: I solve this by making map loop and using index of.

   const pos = arr.map(function(e) { return e.title; });
                if (pos.indexOf(title) === -1){
                    itemsRef.push(movieTitle)
                } else {
                    console.log('Already exist')
                }
KENdi
  • 7,576
  • 2
  • 16
  • 31

0 Answers0