title: Deleting a document from a user specific collection in Firebase
body: <p>I am new to Firebase and working on a small project to get better acquainted with Firebase/Firestore. Right now I'm using Firebase authentication to handle registering and signing in users. Once logged in a list of events is displayed for the user that I created in MySQL and am connecting to my Angular/Ionic app through a http call to Spring. (It was specified for me to do it this way to also learn some Java/Spring.)</p>
  
  <p>I am able to display the events and click to add an event to a user specific "my events" list. I followed the tutorial here: <a href="https://javebratt.com/ionic-firebase-tutorial-object/" rel="nofollow noreferrer">https://javebratt.com/ionic-firebase-tutorial-object/</a></p>
  
  <p>I'm having trouble deleting an event from the users list in Firestore. I'm able to see the specific event ID that gets added by Firestore when the user selects an event to add to "my events" with "event.id" in my *ngFor template in the html. </p>
  
  <p>No matter what I do though I can't get the delete function to work properly. It actually is saying it's running successfully, but nothing is being deleted. I believe I'm missing something between the .doc() and .delete() methods but the Google docs are very vague (or I'm not grasping them correctly).</p>
  
  <p>I've tried specifying a path such as </p>
  
  <pre><code>.doc(`/users/${user.uid}/myEventList/${id}`
  </code></pre>
  
  <p>but that doesn't work. Any help and insight is greatly appreciated.</p>
  
  <p>Here is what I have so far that prints the success message:</p>
  
  <pre><code> removeEvent() {
      this.myEventListRef
        .doc()
        .delete()
        .then(function() {
          console.log("Document successfully deleted!");
        })
        .catch(function(error) {
          console.error("Error removing document: ", error);
        });
    } 
  </code></pre>
  
  <p>Here is my full service.ts: </p>
  
  <pre><code>import { Injectable } from "@angular/core";
  import * as firebase from "firebase/app";
  import "firebase/auth";
  import "firebase/firestore";
  import { Observable } from "rxjs";
  import { HttpClient } from "@angular/common/http";
  import { ToastController } from "@ionic/angular";
  
  @Injectable({
    providedIn: "root"
  })
  export class EventService {
    public myEventListRef: firebase.firestore.CollectionReference;
    public myEventsList: Observable&lt;Event[]&gt;;
    public currentEvent: any = {};
  
    constructor(
      public toastController: ToastController,
      private http: HttpClient
    ) {
      firebase.auth().onAuthStateChanged(user =&gt; {
        if (user) {
          this.myEventListRef = firebase
            .firestore()
            .collection(`/users/${user.uid}/myEventList`);
        }
      });
    }
  
    getEventList(): firebase.firestore.CollectionReference {
      return this.myEventListRef;
    }
  
    copyEvent(
      eventName: string,
      eventPrice: number,
      eventLocation: string,
      eventType: string
    ): Promise&lt;firebase.firestore.DocumentReference&gt; {
      return this.myEventListRef.add({
        name: eventName,
        price: eventPrice,
        location: eventLocation,
        type: eventType
      });
    }
    removeEvent() {
      this.myEventListRef
        .doc()
        .delete()
        .then(function() {
          console.log("Document successfully deleted!");
        })
        .catch(function(error) {
          console.error("Error removing document: ", error);
        });
    }
  
    getEventsObservable(): Observable&lt;any&gt; {
      return this.http.get("http://localhost:8080/events/eventslistX");
    }
  
    async addToMyEventsToast() {
      const toast = await this.toastController.create({
        color: "secondary",
        message: "Added to 'My Events'.",
        duration: 2000
      });
      toast.present();
    }
  }
  </code></pre>
  
  <p>my-events.ts where the user specific events are displayed after they select one from the initial Events list :</p>
  
  <pre><code>import { Component, OnInit } from "@angular/core";
  import { EventService } from "../services/event.service";
  
  import { Observable } from "rxjs";
  
  @Component({
    selector: "app-my-events",
    templateUrl: "./my-events.page.html",
    styleUrls: ["./my-events.page.scss"]
  })
  export class MyEventsPage implements OnInit {
    public myEventsList: Array&lt;any&gt;;
    public currentEvent: any = {};
  
    constructor(private eventService: EventService) {}
  
    ngOnInit() {
      this.eventService
        .getEventList()
        .get()
        .then(eventListSnapshot =&gt; {
          this.myEventsList = [];
          eventListSnapshot.forEach(snap =&gt; {
            this.myEventsList.push({
              id: snap.id,
              name: snap.data().name,
              price: snap.data().price,
              location: snap.data().location,
              type: snap.data().type,
              date: snap.data().date
            });
            return false;
          });
        });
    }
  
    removeEventHandler() {
      this.eventService.removeEvent();
    }
  }
  </code></pre>
  
  <p>And my HTML that displays the users list of events they selected and where I can see the firestore id :</p>
  
  <pre><code>&lt;ion-content&gt;
    &lt;ion-card *ngFor="let event of myEventsList; index as i"&gt;
      &lt;ion-card-header&gt;
        &lt;ion-card-title&gt;{{ event.id }}&lt;/ion-card-title&gt;
        &lt;ion-card-title&gt;{{ event.name }}&lt;/ion-card-title&gt;
        &lt;ion-card-subtitle&gt;$ {{ event.price }}&lt;/ion-card-subtitle&gt;
        &lt;ion-card-subtitle&gt;City: {{ event.location }}&lt;/ion-card-subtitle&gt;
        &lt;ion-card-subtitle&gt; Type of event : {{ event.type }}&lt;/ion-card-subtitle&gt;
        &lt;ion-icon
          name="close-circle"
          color="danger"
          (click)="removeEventHandler()"
        &gt;&lt;/ion-icon&gt;
      &lt;/ion-card-header&gt;
    &lt;/ion-card&gt;
  &lt;/ion-content&gt;
  
  </code></pre>