How can I get last created document in couchdb? Maybe some how I can use _changes feature of couchdb? But documentation says, that I only can get list of document, ordered by first created document, ant there is no way to change order.
So how can I get last created document?
Your only surefire way to get the last created document is to include a timestamp (created_at
or something) with your document. From there, you just need a simple view to output all the docs by their creation date.
I was going to suggest using the last_seq
information from the database, but the sequence number changes with every single write, and replication also complicates the matter further.
You can get the changes feed in descending order as it's also a view.
GET /dbname/_changes?descending=true
You can use limit= as well, so;
GET /dbname/_changes?descending=true&limit=1
will give the latest update.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With