title: What strategy to take if MongoDB is down and operations are pending
body: <p>I have a List where each Employee has a Manager assigned. So for each object has a Manager reference in it, which is not a manager id, but a set of fields by which we can identify a manager.</p>
  <p>Each Manager object has list of references of Employees</p>
  <p>So classes look like this</p>
  <pre><code>Class Manager {
  
  ObjectId _id;
  
  //some attributes
  
  List&lt;Employees&gt; employees;
  
  LocalDateTime createdOn;
  
  }
  
  </code></pre>
  <pre><code>
  Class Employee {
  
  ObjectId _id
  
  //some attributes
  
  Manager manager; //Having only attributes but not ObjectId of manager
  
  LocalDateTime createdOn;
  
  }
  
   
  </code></pre>
  <p>We have done this because names and some attributes of this manager can be changed and hence a new Manager Object can be introduced in the Manager collection and then all the existing employees will now belong to the new manager object. That’s how our structure is.</p>
  <p>While querying, we will get attributes of a Manager, and we return back List of Employees of the manager who is latest according to the attributes and a createdOn field</p>
  <p>So the problem which I’m facing is:</p>
  <p>While saving a new List of Employees which belong to a new Manager, I first save all the Employees using insertMany() function of mongoClient. Then I save the Manager using insert().</p>
  <p>If after saving the Employee list and before saving the Manager, something bad happened to Mongo and Db is down so I won’t be able to save the Manager, hence all Employees will now be orphaned.</p>
  <p><strong>What strategies I can follow in order to ensure that when MongoDB comes up again, I can first store all the pending objects and then continue with the rest of the operations.</strong></p>
  <p>I'm using SpringBoot 2 with Raw Mongo Java driver 3.8.0 and Java 8</p>
  <p>I have tried Mongo retry writes option but that only tries once</p>