In my web project, I have older and newer buttons. If I click on older it has to display previous blog details n vice versa for newer. Now I am passing current id in the backend and I have to search and find previous id in MongoDB. How to get that. If any links related to this please provide.
This is piece of code where I am taking current id:
Controller.js:
$scope.previousBeat = function(beatId){
var beatId = beatId;
blogService.getPreviousBlog(beatId, function(data){
$scope.blogId = data;
})
};
In service.js:
this.getPreviousBlog = function(id, callback){
var url = 'blog/' + id + '/details';
httpService.getRequest(url, callback);
};
In controller.java:
@RequestMapping(value = "/{id}/details", method = RequestMethod.GET)
public @ResponseBody Blog getPreviousBlogWithId(@PathVariable("id") String id) {
try {
Blog blog = blogService.findBlogById(id);
return blogService.incrementViewCount(blog);
} catch (Exception e) {
// log.error("Error while retrieving blog", e.getMessage());
}
return null;
}
Service.java:
@Override
public Blog findBlogById(String id) {
Blog blog = blogRepo.findOne(id);
find().sort({_id:1})
if (blog != null) {
return blog;
}
return null;
}
Is there any way to get previous id.