0

I'm using flask and pymongo to create a website, but my database has some problems.

I want to display the 3 most recent keys (most recent uploads) first but I can't figure out how.

@app.route("/")
def slash():
  data = music.find({},{"_id":-1})
  return render_template("index.html", artists=data)

Thanks in advance, been stuck on this for awhile.

I tried to get the top 3 keys to be in decending order

_id: 3,
_id: 2,
_id: 1

instead alot of errors happened and when i tried using sorted it just outputted

_id: 1,
_id: 2,
_id: 3
davidism
  • 121,510
  • 29
  • 395
  • 339
ksiscool
  • 1
  • 3
  • 1
    Does this answer your question? [How to sort mongodb with pymongo](https://stackoverflow.com/questions/8109122/how-to-sort-mongodb-with-pymongo) – Belly Buster Oct 27 '22 at 23:19
  • i actually figured this out yesterday after posting this question using *about* the same solution – ksiscool Oct 28 '22 at 13:06

0 Answers0