Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:50:56+00:00 2026-05-24T12:50:56+00:00

Using mysql this would be: SELECT * FROM thetable ORDER BY id DESC LIMIT

  • 0

Using mysql this would be:

SELECT * FROM thetable ORDER BY id DESC LIMIT 10

How can I do this in couchdb for all documents with “type”:”message”? (without pulling all documents with type:message)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:50:58+00:00Added an answer on May 24, 2026 at 12:50 pm

    Create a view that emits all doc ids. The view keys will be used for sorting automatically.

    function(doc) {
        if(doc.type && doc.type === 'message'){
            emit(doc._id, null);
        }
    }
    

    Then execute a query: http://host/yourdb/_design/yourdesigndoc/_view/viewname?limit=10&include_docs=true&descending=true

    Because you want the full document, we didn’t included anything as value in the view. Instead, we add include_docs=true to fetch every full document for the view entries.

    Note that there is also a builtin view that does the same: http://host/yourdb/_all_docs?limit=10&include_docs=true&descending=true

    PS: You should be aware of the fact that CouchDB by default uses UUIDs as IDs, which will render the sorting more or less useless, if you really want to get the latest docs. Either provide your own incremental IDs (what about distribution/replication?) or use a new field that stores the time the doc has been created and use in the view as well.


    If your docs have a created field (i.e. UNIX timestamp, JavaScript Date.now() or even a RFC 3339-like string), you can build an index on these values.

    Here is the time-based view:

    function(doc) {
        if(doc.type && doc.type === 'message' && doc.created){
            emit(doc.created, null);
        }
    }
    

    Note that we will not emit the doc._id itself. However, CouchDB stores the doc._id where the data came from for each emitted key/value pair automatically, so we can again use include_docs=true to fetch the complete docs.

    Query http://host/yourdb/_design/yourdesigndoc/_view/viewname?limit=10&include_docs=true&descending=true

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MySQL. I have several lookups like this: SELECT * from users
I've found a few answers for this using mySQL alone, but I was hoping
This is a winform and I'm using mysql as a database, here is my
I'm using MySQL with PHP. This is like my table: (I'm using 3 values,
I'm using MySQL 5, and I need to do this sentence to get the
I am trying to implement an application by using MySQL/JAVA and I found this
I've got this toy code, works fine, using MySQL var r = new SimpleRepository(DB,
I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement(
Im using this code for mysql connection $con = mysql_connect(localhost:/var/lib/mysql/mysql.sock, abc , xyz); if
I'm using this code and I'm beyond frustration: try { $dbh = new PDO('mysql:dbname='

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.