Home > Blockchain >  How can I write the following mongodb query in springboot?
How can I write the following mongodb query in springboot?

Time:05-12

Query -- 
db.collection.find().sort({$natural: -1}).limit(5)

This query looks for the most recent 5 documents of a collection

How can I write the following in springboot?

CodePudding user response:

Use find method from Spring Data MongoDB repository or template with the following Query

new Query().with(Sort.by(Direction.DESC, "$natural")).limit(5);
  • Related