I have a MongoDB object which was created using a Map<String, List>. I'm trying to add CRUD methods to EDIT and DELETE objects from the arrays within the object. This is how the JSON structure looks like:
[
{
"id": "1",
"courses": {
"Spring": [
{
"subject": "Electrical Engineering",
. . .
"id": "123"
}
],
"Fall": [
{
"subject": "Electrical Engineering",
. . .
"id": "456"
},
{
"subject": "Computer Science",
. . .
"id": "789"
}
]
}
}
]
I was trying to use pull() method to remove the object but I get an exception
org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting to connect.
Here is the method in the Service class that tries to delete
public void delete(String semester, String id){
// Object.Array
String object = "courses." + semester;
Update update = new Update().pull(object, Collections.singletonMap("_id", id));
mongoOps.updateMulti(new Query(), update, Courses.class);
}
Courses.java
@Document
public class Courses {
@Id
private String ID;
private String semester;
. . .
}
Semester.Java
@Document
public class Semester {
@Id
String id;
Map<String, List<Courses>> courses = new HashMap<String, List<Courses>>();
...
}