Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2488

What strategy to take when MongoDB is down and operations are pending

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      I have a List<Employee> 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.

      Each Manager object has list of references of Employees

       

      So classes look like this

       

      Class Manager {
      ObjectId _id;
      //some attributes
      List<Employees> employees;
      LocalDateTime createdOn;
      }
      

       

       

       

      Class Employee {
      ObjectId _id
      //some attributes
      Manager manager; //Having only attributes but not ObjectId of manager
      LocalDateTime createdOn;
      }
      

       

       

       

      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.

      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

       

      So the problem which I’m facing is:

      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().

      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.

       

      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.

       

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            bhutani.mohit91 Mohit Bhutani
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: