0

I want to make a function deleteEmployee(String companyName, String departmentName, String employeeName);

Its job is to delete an employee item of the employees list inside a departments array which is inside a company entry. The structure of the BSON is as follows :

{ 
    "name" : "company1" , 
    "departments" : [ 
        { 
            "name" : "science" , 
            "employees" : [ 
                {
                    "name" : "alex"
                } , 
                {   
                    "name" : "john"
                } 
            ]
        } , 
        { 
            "name" : "arts" , 
            "employees" : [ 
                { 
                    "name" : "bob"
                } , 
                { 
                    "name" : "david"
                } 
            ]
        }
    ]
}

How is that possible?

TechWisdom
  • 3,960
  • 4
  • 33
  • 40
Melki99
  • 1
  • 3
  • Possible duplicate of http://stackoverflow.com/questions/5228210/how-to-remove-an-element-from-a-doubly-nested-array-in-a-mongodb-document – Vishnu Jul 17 '15 at 17:26
  • What have you tried so far? Are you able to write the query that deletes the employee item without using java driver first? – Jhanvi Jul 22 '15 at 11:29
  • I managed the deletion using a department index in "departments" array. You can check my solution here :(https://github.com/medmelki/peopledirectory/blob/master/src/main/java/org/kapit/peopledirectory/dao/impl/CompanyDAOImpl.java#L90) but really isn't a good one. – Melki99 Jul 23 '15 at 12:26

0 Answers0