title: How to delete a document in a collection in Firebase/Firestore using its id?
body: <p>I have a page in my application(in angular) where the user can post a comment. 
  The comment is stored in Firestore collection with the name of "comments". The user should be able to delete the comment once he clicks the delete button next to it.</p>
  
  <p>My <strong>comments.component.ts file</strong> code is as below -</p>
  
  <pre><code>import { Component, OnInit, Input} from '@angular/core';
  import * as firebase from 'firebase/app';
  import 'firebase/auth';
  import 'firebase/firestore';
  
  @Component({
  selector: 'app-comments',
  templateUrl: './comments.component.html',
  styleUrls: ['./comments.component.css']
  })
  export class CommentsComponent implements OnInit {
  
  comment : string;
  allcomments : any[]=[];
  @Input('postId') postId : string;
  cid : any;
  
  constructor() { }
  
  ngOnInit(){
  
  this.getComments();
  
  }
  
  postComment(){
  firebase.firestore().collection("comments").add({
  comment : this.comment,
  post: this.postId,
  owner: firebase.auth().currentUser.uid,
  ownerName : firebase.auth().currentUser.displayName,
  created: firebase.firestore.FieldValue.serverTimestamp()
  
  }).then((data) =&gt;{
   // console.log(data);
   this.getComments();
   console.log("commID",data.id);
   this.cid = data.id;
  
   }).catch((error)=&gt;{
    console.log(error)
   })
  }
  
  getComments(){
  
  this.allcomments = [];
  firebase.firestore().collection("comments")
  .where("post","==",this.postId)
  .orderBy("created","desc")
  .get().then((data)=&gt;{
  
    data.docs.forEach((commentRef)=&gt;{
    this.allcomments.push(commentRef.data())
  
    })
  
  })
  .catch((error)=&gt;{
    console.log(error)
  })
  
  }
  
  onDelete(){
  
   //console.log("INSIDE DELETE")
   console.log(this.cid)
   firebase.firestore().collection("comments").doc(this.cid).delete()
   .then(()=&gt;{
  
    console.log("DELETED")
   }).catch((error)=&gt;{
    console.log(error)
   });
  
  }
  }
  </code></pre>
  
  <p>The delete function takes cid as null. My question is, how can I pass the correct comment id of the comment I am trying to delete to the onDelete() function ?</p>
  
  <p>I am a beginner. Please excuse me if this sounds trivial.</p>
  
  <p>Thanks in advance !!</p>