1

I need to save the document id in collection. Mean when user save data it will also save the document id with data. Can any one please tell how can i do this. Thanks :)

  create() {
     // the user details are updated in firebase user list
     this.groupDetails = {
       groupname: this.Name,
       description: this.description,
       members: this.checked,
       messages: [],
       createdId: this.user.userId,
       createrName: this.user.username
     }
     console.log(this.groupDetails);
    // details are submitted to creatGroup function from groupProvider
     this.messageService.createGroup(this.groupDetails).then(resp => {
      console.log(resp);
      this.toast.show("Group Created");
      this.router.navigate(["/home"]);
     });

   }

  createGroup(groupDetails) {
    return this.angularFirestore.collection('Groups').add(groupDetails);
  }
0

1 Answer 1

1

I am doing like this now if any one have better answer so its also great

  createGroup(groupDetails) {
    return this.angularFirestore.collection('Groups').add(groupDetails).then(ref => {
      ref.set({ group_id: ref.id }, { merge: true }).then(() => {
      console.log("Group id is added");
      });
  })
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.