[CSHARP-2488] What strategy to take when MongoDB is down and operations are pending Created: 25/Jan/19 Updated: 14/Jun/19 Resolved: 06/Feb/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Mohit Bhutani | Assignee: | Wan Bachtiar |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
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
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.
|
| Comments |
| Comment by Wan Bachtiar [ 04/Feb/19 ] |
Hi Mohit, First, consider changing the data model design for Employee to have a reference to a Manager, instead of a Manager having an uncapped list of employees. You may also find the following resources useful: Please note that the CSHARP project is for reporting bugs or feature suggestions for the MongoDB .NET/C# driver. If you have any follow-up questions on the use of the driver, please post a question on mongodb-user group with relevant the information. Regards, |