When I enter this into my console, it works:
db.posts.find({"_id": {$lt:ObjectId("55732dccf58c555b6d3f1c5a")}}).limit(5).sort({"_id":-1})
When I use mongotemplate, it does not work and returns an empty array:
@RequestMapping(value="/next", method=RequestMethod.GET)
public List getNextPost(@RequestParam String next) {
Query query = new Query();
query.addCriteria(Criteria.where("_id").lt("55732dccf58c555b6d3f1c5a"));
List<Posts> posts = template.find(query, Posts.class);
return posts;
}
I tried it with this query, and it works, but returns only the specific record associated with the identifier:
query.addCriteria(Criteria.where("_id").is("55732dccf58c555b6d3f1c5a"));
I also tried with Basic Query and did this, and it also returns an empty array:
BasicQuery query1 = new BasicQuery("{'_id': {$lt:'ObjectId(\"55732dccf58c555b6d3f1c5a\")'}}).limit(5).sort({'_id':-1}");
I'm at a dead end. How can I return all documents under a specific Mongo ObjectID in the database?
Simon source
share