Reputation: 2233
I am trying to get objects from Mongodb in ascending (or descending) timestamp order.
This is how the document looks like:
{
_id: 5b01ffe3cd8b295aed16d5c0Wed
temperature: 23
timestamp: Dec 13 09:27:00 CET 2017
}
I am using Spring repository:
public interface TemperatureRepo extends MongoRepository<TemperatureObject, String> {
public List<TemperatureObject> findAllByOrderByTimestampDesc();
}
But somehow, Desc and Asc queries never work. I always get the result set in same order (which is not ordered at all)
The attribute temperature
is saved as Date
not as String
Is this a bug or am I missing something?
Upvotes: 0
Views: 1942
Reputation: 1008
try this, it will solve your problem.
List<TemperatureObject> temperatureObjects = temperatureRepo.findAll(new Sort(Sort.Direction.DESC, "timestamp"));
Upvotes: 1