0

I have a find query as given below

POST /movies/_find HTTP/1.1
Accept: application/json
Content-Type: application/json
Content-Length: 168
Host: localhost:5984

{
    "selector": {
        "year": {"$gt": 2010}
    },
    "fields": ["_id", "_rev", "year", "title"],
    "sort": [{"year": "asc"}],
    "limit": 2,
    "skip": 0
}

Which returns the first two results that match the query. Is it possible to get the total number of rows with this query. This is very useful when building pagination

2 Answers 2

1

No, sorry. In order to do so, the query would need to trawl the whole set to count. Note that text indexes already support pagination out of the box:

https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html#finding-documents-by-using-an-index

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I ended up using search API and it returned total rows
1

You can get meta data of the DB using GET /movies

total number of rows - "doc_count"

Response example:

    {
      "update_seq": "<some data>",
      "db_name": "movies",
      "sizes": {
        "file": <size>,
        "external": <size>,
        "active": <size>
      },
      "purge_seq": 0,
      "other": {
        "data_size": <size>
      },
      "doc_del_count": <number>,
      "doc_count": <number>,
      "disk_size": <size>,
      "disk_format_version": <version>,
      "compact_running": false,
      "instance_start_time": "0"
    }

1 Comment

how to apply "selector": { "year": {"$gt": 2010} } for this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.