Reputation: 1227
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);
}
Upvotes: 1
Views: 77
Reputation: 1227
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");
});
})
}
Upvotes: 1