I am trying to add a set of data to a database by pushing the data to an array and adding them to the database. I have added my codes here
const com = {
company: "Com",
description: "Turn ...",
pointsNeeded: "500",
title: "Com",
PromoCode: Math.floor(Math.random()*1000000000),
imageLocation: "www...",
}
this.afDB.list('rewards/' + se.uid).push(com)
.then(next => {
console.log(next);
});
This is how my database look like
However, I would like the database to be like
"rewards" : {
"fH7GPHMFupW2JD8fxKnLOvHBZ0w1" : {
0: {
"PromoCode" :
"company" :
"description" :
"imageLocation" :
"pointsNeeded" :
"title" :
},
1" : {
"PromoCode" :
"company" :
"description" :
"imageLocation" :
"pointsNeeded" :
"title" :
}
}
}
Can anyone advice? I am not really sure what to do next. Thanks
UPDATE:
const getUserReward = firebase.database().ref('rewards/').child(se.uid)
getUserReward.once('value', data => {
var rewardArray =[];
rewardArray.push(comchestReward)
getUserReward.update({rewards: rewardArray})
})
So this is the code I have so far but it is now
1 post - 1 participant