title: MongoRepository Delete Method
body: <p>Good afternoon fellow coders!</p>
  <p>I have spent the last hour looking to delete a single document from my mongo &quot;testCollection&quot;.  I would like to make use of the MongoRepository delete / deleteAll methods.  However, it does not remove the document.  It persists regardless of how many times I run the test class method.  No errors are reported and the user has readWrite permissions in the database.  I am able to run the mongo command to remove the newly created test document.</p>
  <p>I have read about using the mongo template and create it for the deletion to be performed.  I'm happy to do that but I would rather keep it as simple as possible.</p>
  <pre><code>import lombok.Data;
  import org.springframework.data.mongodb.core.mapping.Document;
  import org.springframework.data.mongodb.core.mapping.MongoId;
  
  @Data
  @Document(collection = &quot;testCollection&quot;)
  public class TestClass {
      @MongoId
      private String id;
  
      private String name;
  
      public TestClass(String name) {
          this.name = name;
      }
  }
  </code></pre>
  <p><strong>Test Class Mongo Repository interface</strong></p>
  <pre><code>import org.springframework.data.mongodb.repository.MongoRepository;
  import java.util.List;
  
  public interface TestClassRepository extends MongoRepository&lt;TestClass, String&gt; {
      public List&lt;TestClass&gt; findAllByName(String name);
      public void deleteAllByIdIn(List&lt;TestClass&gt; list);
  }
  </code></pre>
  <p><strong>Test Method</strong></p>
  <pre><code>import org.junit.Assert;
  import org.junit.Test;
  import org.junit.experimental.categories.Category;
  import org.junit.runner.RunWith;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.TestPropertySource;
  import org.springframework.test.context.junit4.SpringRunner;
  
  import java.util.List;
  
  @RunWith(SpringRunner.class)
  @TestPropertySource(value = {&quot;classpath:application.properties&quot;})
  @AutoConfigureMockMvc
  public class testClassTest {
      @Autowired
      private TestClassRepository testClassRepository;
  
      @Test
      public void crudTest() {
  
          TestClass testObj = new TestClass(&quot;Test&quot;);
          testClassRepository.save(testObj);
  
          List&lt;TestClass&gt; testClassList = testClassRepository.findAllByName(&quot;Test&quot;);
          Assert.assertEquals(1, testClassList.size());
  
          TestClass test = testClassList.get(0);
          testClassRepository.deleteAllByIdIn(testClassList);
  
          // Fails this assertion: Found 1, expected 0.
          Assert.assertEquals(0, testClassRepository.findAllByName(&quot;Test&quot;).size());
      }
  }
  </code></pre>
  <p>As anyone else experienced a similar issue?  If so, how'd you go about resolving it?</p>
  <p>Thanks!</p>
  <p>Additions to original post:</p>
  <ol>
  <li>Here is the mongo query generated by the MongoRepository.  It appears that it is not actually adding the &quot;remove&quot; mongo command to the query.  <em>Query: { &quot;name&quot; : &quot;Test&quot;}, Fields: {}, Sort: {}</em></li>
  </ol>