title: How to delete Item from firestore in android with auto-generated document ID
body: <p>I have a Firestore database with the following structure in a hierarchical form:</p>
  <p><strong>collection(&quot;notes&quot;) &gt; document(currentUserId) &gt; collection(&quot;mynotes&quot;) &gt; document(auto-generated-key) &gt; items...</strong></p>
  <p>I have added data to the Firestore as follows :</p>
  <pre><code>   mAuth = FirebaseAuth.getInstance();
     database = FirebaseFirestore.getInstance();
    
     //here scheduleModel is a model class with constructor(String, boolean, String) with getters and 
     //setters for three of them 
     scheduleNoteModel = new ScheduleNote(noteTitle, isImp, strDate);
  </code></pre>
  <p>I have added the note item like this.</p>
  <pre><code>database.collection(&quot;notes&quot;).document(mAuth.getUid())
              .collection(&quot;mynotes&quot;)
              .document() //generated id automatically...
              .set(scheduleNoteModel)
              .addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
                  @Override
                  public void onSuccess(Void aVoid) {
                      Toast.makeText(getContext(), &quot;data added ...&quot;, Toast.LENGTH_SHORT).show();
                      etNoteTitle.setText(&quot;&quot;);
                      //dismiss (hide) the bottom sheet after adding item
                      BottomSheetScheduleFragment.this.dismiss();
  
                      //refresh the fragment
                  }
              });
  </code></pre>
  <p>The problem is getting that id back while deleting the item. I know there are many questions similar to this, some of them were good but I couldn't figure out to solve them. I had a look at <a href="https://stackoverflow.com/questions/49361039/deleting-a-document-from-firestore-via-auto-generated-document-id">this link</a> solution but I wasn't able to solve</p>
  <p>In adapter</p>
  <pre><code> holder.deleteNoteIcon.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              deleteNote(noteModel);
          }
      });
  
  
  Method to delete
  
      private void deleteNote(ScheduleNote note, int itemPosition, View view) {
      mAuth = FirebaseAuth.getInstance();
      database = FirebaseFirestore.getInstance();
  
      //getting the doc id of auto-generated code in Firestore.
       String id = database.collection(&quot;notes&quot;).document(mAuth.getUid()).collection(&quot;mynotes&quot;).document().getId();
  
      Toast.makeText(context, &quot;position &quot; + itemPosition + &quot;doc id &quot; + id, Toast.LENGTH_SHORT).show();
  
      database.collection(&quot;notes&quot;).document(mAuth.getUid())
              .collection(&quot;mynotes&quot;)
              //.document(&quot;72NMkKY73CXHVN7DFE8W&quot;) get that id automatically
              .document(id)
              .delete()
              .addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
                  @Override
                  public void onSuccess(Void aVoid) {
                      //notifyDataSetChanged();
                      Snackbar snackbar = Snackbar.make(view, &quot;Note Deleted successfully&quot;, Snackbar.LENGTH_SHORT);
                      snackbar.show();
                  }
              });
  }
  </code></pre>
  <p>id in the above variable isn't matching the real id. How to get that id?</p>
  <p>I basically want two information for this :</p>
  <ol>
  <li>How to get the document Id before adding it to the Firestore so that I can attach this to my model class and later on delete based on that ID, has any solution?</li>
  <li>Or, just get the document Id by the Model Class that I pass when clicking on the item in RecyclerView?</li>
  </ol>
  <p>I actually did a lot of research but couldn't figure it out. Any quick help would be appreciated, thanks.</p>