I want to update an instance in realtime DB if the value exist
If in realtime DB have a same date with today, push the new data inside the resi
So each date have a lot of array inside the resi
I tried this thing, it created a new instance inside the db
firebase
.database()
.ref('resi-list')
.orderByChild("date")
.equalTo(moment().format('dddd, MMMM Do YYYY'))
.once('value')
.then(snapshot => {
if (snapshot.val()) {
firebase
.database()
.ref('resi-list')
.child(snapshot.val().key)
.update({
resi: [{
noResi: resiForm.noResi,
type: resiForm.type,
}]
})
.then(res => AlertInfo('Success', 'Success Post Data!', 'success'))
.catch(err => AlertInfo('Oops', 'Error Post Data!', 'Error'));
} else {
firebase
.database()
.ref(`resi-list`)
.push({
date: moment().format('dddd, MMMM Do YYYY'),
resi: [{
noResi: resiForm.noResi,
type: resiForm.type,
}],
})
.then(res => {
AlertInfo('Success...', 'Success Post Data', 'success');
fetchResiList();
})
.catch(err => AlertInfo('Oops', 'Error Post Data', 'Error'));
}
}).catch(err => console.log(err));