Ionic 4 firestoe如何在数据中保存ID?

问题描述 投票:0回答:1

我需要将文档ID保存在集合中。意味着当用户保存数据时,它还将保存文档ID和数据。谁能告诉我该怎么做。谢谢:)

  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);
  }
angular ionic-framework google-cloud-firestore
1个回答
0
投票

如果有人有更好的答案,我现在就这样做,它也很棒

  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");
      });
  })
}
© www.soinside.com 2019 - 2024. All rights reserved.