title: Why deleteOne & findById of mongoose work on deleted id
body: <p>Currently developing an API with nodejs that communicates with a MongoDB database, I noticed a special behavior after deleting a document.</p>
  
  <p>Indeed, my API has several endpoints that allow to retrieve all the animals in the database, to retrieve a specific one using the corresponding id or to delete a specific one, again using the id of the document to delete.</p>
  
  <p>The results I don't understand happen once a document is deleted. Indeed, as you can see in the picture below, when I delete the document of the animal called "Johnny" the queries to find it via its id or to delete it via the same ID continue to work, even if the get returns nothing and the deletion indicates that no operation has been performed.</p>
  
  <p><a href="https://i.stack.imgur.com/CoN3J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CoN3J.png" alt="enter image description here"></a> </p>
  
  <p>Personally I expected the same behavior as if I passed a wrong id for a deletion (visible below), but if the id has already been assigned in the database the queries work even after a deletion.</p>
  
  <p><a href="https://i.stack.imgur.com/1Ar8S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1Ar8S.png" alt="When I tried to deleted a wrong ID"></a></p>
  
  <p>Does MongoDB have a "cache" of deleted documents in order to perform a rollback in case of unwanted deletion?</p>
  
  <p>You will find below the different endpoints that use find, deleteOne &amp; findById</p>
  
  <pre class="lang-js prettyprint-override"><code>
  exports.getAllAnimal = (req, res, next) =&gt; {
      Animal.find().sort({'customer' : 1})
      .then(animals =&gt; res.status(200).send(animals))
      .catch(error =&gt; res.status(400).send({ error: error.message }));
  };
  
  
  exports.getOneAnimal = (req, res, next) =&gt; {
      Animal.findOne({ _id: req.params.id })
          .then(animal =&gt; res.status(200).send(animal))
          .catch(error =&gt; res.status(400).send({ error: error.message }));
  };
  
  
  exports.deleteAnimal = (req, res, next) =&gt; {
      Animal.deleteOne({ _id: req.params.id })
          .then(thing =&gt; res.status(200).send({ message : 'Animal successfully deleted'}))
          .catch(error =&gt; res.status(400).send({ error: error.message }));
  
  };
  
  </code></pre>