I need to do the following sql query using spring data api:
Select * from TagTest where tagName = "water temperature" Order by timestamp desc;
I came up with the query:
Query query = new Query(Criteria.where("tagName").is("water temperature"));
I defined Sort as:
query.sort().on("timestamp", Order.DESCENDING);
and the using mongoTemplate do findOne() like:
mongoTemplate.findOne(Collection, query, MongoTag.class);
But I cannot find a way to apply the sort to retrieve results in findOne.
Is the approach correct? Please let me know the correct approach in case I am wrong.
Thanks.
mongoTemplate.findOne(Collection, query, MongoTag.class);in a for loop and are you adding it to an ArrayList or an Array? if not, then you won't be able to sort from 1 single returned value.