How to write data to firebase by Ionic without erasing what is already saved?

Asked

Viewed 54 times

0

My Create method is like this

create(user: User, uuid: string): Promise<void> {
return this.db.object(`/users/${uuid}`)
  .set(user)
  .catch(this.handlePromiseError);
}

And my User class is like this

export class User {

public $key: string;

constructor(
    public name: string,
    public username: string,
    public email: string,
    public photo: string
) {}

}

Only when I go to record in firebase, the id becomes undefined and when I record another data it overrides the first one and erases.

inserir a descrição da imagem aqui

  • https://firebase.google.com/docs/firestore/manage-data/transactions?hl=pt-br Use transactions. This should solve your problem.

1 answer

0

Try making a push():

create(user: User): Promise<void> {
return this.db.object(`/users`)
  .push(user)
  .catch(this.handlePromiseError);
}
  • The push is giving error

  • Are you saying that push does not exist in Angularfireobject

Browser other questions tagged

You are not signed in. Login or sign up in order to post.