I want to fetch third level children I try this ways but it is not working.
{
"title": "box",
"active": false,
"level": "you",
"children": [
{
"id": 1,
"title": "hood",
"type": "uod",
"active": false,
"level": "9",
"children": [
{
"id":1,
"title": "New",
"type": "hog",
"active": false,
"level": "3",
}
]
}
]
}
I want to find one nested record with Id in mongo db spring boot. But getting NullPointerException
how to handle it with this code.
This my Get Apis
@GetMapping("/menus/{id}/submenu/{subId}/children/{childId}")
public List<?> findChildrenById(@PathVariable("id") long id,
@PathVariable("subId") long subId, @PathVariable("childId") long childId) {
Query query = new Query();
query.addCriteria(Criteria.where("id").is(id).and("children.id").is(subId).and("children.children.id").is(childId));
return operations.findOne(query, SubMenu.class).getChildren();
}
Error
"java.lang.NullPointerException: Cannot invoke "com.menu.entity.SubMenu.getChildren()" because the return value of "org.springframework.data.mongodb.core.MongoOperations.findOne(org.springframework.data.mongodb.core.query.Query, java.lang.Class)" is null\r\n\tat com..menu.controller.MenuItemsGetControlller.findChildrenById(MenuItemsGetControlller.java:84)\r\n\tat