title: deleting a mongodb document which is associated with ng-repeat gives "Duplicates in a repeater are not allowed"
body: <p>I am retrieving an entire "collection" from my mongodb database as array of json objects, "tests".</p>
  
  <p>The "tests" is in following format</p>
  
  <pre><code>[{...},{...},{...}]
  </code></pre>
  
  <p>I am using this array to populate a table in html using ng-repeat in angularjs.</p>
  
  <pre><code>      &lt;table class="table table-bordered"&gt;
          &lt;thead class="thead-dark"&gt;
            &lt;tr&gt;
              &lt;th scope="col"&gt;#&lt;/th&gt;
              &lt;th scope="col"&gt;Title&lt;/th&gt;
              &lt;th scope="col"&gt;Start Date&lt;/th&gt;
              &lt;th scope="col"&gt;End Date&lt;/th&gt;
              &lt;th scope="col"&gt;Time&lt;/th&gt;
              &lt;th scope="col"&gt;Duration&lt;/th&gt;
              &lt;th scope="col"&gt;Total Marks&lt;/th&gt;
              &lt;th scope="col"&gt;Pass Marks&lt;/th&gt;
              &lt;th scope="col"&gt;&lt;/th&gt;
              &lt;th scope="col"&gt;&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
            &lt;tr data-ng-repeat="test in tests" id="testId_{{$index}}"&gt;
              &lt;th scope="row"&gt;{{$index}}&lt;/th&gt;
              &lt;td&gt;{{test.title}}&lt;/td&gt;
              &lt;td&gt;{{test.startDate}}&lt;/td&gt;
              &lt;td&gt;{{test.endDate}}&lt;/td&gt;
              &lt;td&gt;{{test.startTime}}&lt;/td&gt;
              &lt;td&gt;{{test.duration}}&lt;/td&gt;
              &lt;td&gt;{{test.totalMarks}}&lt;/td&gt;
              &lt;td&gt;{{test.passMarks}}&lt;/td&gt;
              &lt;td&gt;&lt;a href="#" ng-click="deleteTest($index)" class=""&gt;Delete&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href="#" ng-click="modifyTest($index)" class=""&gt;Modify&lt;/a&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
  </code></pre>
  
  <p>Which works correctly.</p>
  
  <p><a href="https://i.stack.imgur.com/AKc81.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AKc81.png" alt="enter image description here"></a>
  I can also add more "collections" to the database and the table grows.
  But I want to delete "collections" as well from the database and the table must shrink.</p>
  
  <p>Here is the (little messy) controller doing this,</p>
  
  <pre><code>examApp.controller('adminSetTestsController', ['$element', '$compile', '$scope', 'store', '$state', 'Service', 'userAuth', 'testService', function($element, $compile, $scope, store, $state, Service, userAuth, testService) {
      var testId = userAuth.getTestId();
      $scope.tests = [];
  
      testService.retrieveTest() //service to get all the collections in the db using "testModel.find({});"
      .then(function(response){
         $scope.tests = response;
         console.log('retrieveTest-response:',response);
      })
      .catch(function(error) {console.log('err:',error)});
  
      $scope.deleteTest = function(index){
         $scope.$index = index;
         var testId = $scope.tests[$scope.$index]._id;
         console.log('testId:',testId);
  
         $scope.tests.splice(index, 1);
  
         //Comment this deletion part and the error vanishes.
         testService.deleteTest(testId) //service to delete the "collection" with _id == testId.
         .then(function(response){
             $scope.tests = response;
             console.log('deleteTest-response:',response);
         })
         .catch(function(error) {console.log('err:',error)})
      }
  }])
  </code></pre>
  
  <p>Again it works, but also gives this error.</p>
  
  <p><a href="https://i.stack.imgur.com/Q4u5K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q4u5K.png" alt="enter image description here"></a></p>
  
  <p>The error pops up whenever the delete operation is performed.</p>
  
  <p>The error vanishes if the "collection" deleting part of the code is commented out.<br>
  So I guess it has to do something with deletion of database collection which is associated with ng-repeat.<br></p>
  
  <p>I have tried solutions provided in <a href="https://docs.angularjs.org/api/ng/directive/ngRepeat" rel="nofollow noreferrer">https://docs.angularjs.org/api/ng/directive/ngRepeat</a>, <a href="https://stackoverflow.com/questions/30782127/how-to-remove-object-from-array-within-ng-repeat-with-angularjs">How to remove object from array within ng-repeat with AngularJS?</a> and some other but they all seem to be talking about deleting an item from the array not the database.<br></p>
  
  <p>Assume that I am pretty new at angularjs.</p>