How do I add a uniqueId for each entry to Firebase on a push? Right now my code looks like:
this.games.push({
game_name: data.gameName,
number_of_players: data.number_of_players,
random_id: this.randomId,
admin: data.admin,
first_name: data.your_name,
player_array: [this.combinePlayerName(this.firstName, this.admin)]
})
I'm using AngularFire2 and grabbing a database reference to this.games:
constructor(public navCtrl: NavController, public alertCtrl: AlertController, af: AngularFire) {
this.games = af.database.list('/games');
this.ids = af.database.list('/games/random_id');
}
How do I push to the DB and instead of getting a list that looks like this with randomly generated Id's:
I get a list of intentional Id's that I have knowledge of and can select in the client code?
set
orupdate
with any ID you like as the key, but the onus is then on you to ensure the keys are unique. Typically, the use of push is encouraged for that reason.game_name
,first_name
, etc. Is that what you mean?