How do I do this simple thing, I just want the number of documents in a database. So far I am using a loop function in python to do this, but it seems an incredible inefficient way of doing this. Fauton tells you at the bottom of the page how many docs there are, how can i get this number in either python or javascript please?
Asked
Active
Viewed 5,657 times
2 Answers
5

OrangeDog
- 36,653
- 12
- 122
- 207
-
Couldn't get "GET" statement to work, but the python one works a treat, which is perfect, thank you. – iFunction Mar 13 '17 at 14:06
-
1It's not a "statement", it's an HTTP request. – OrangeDog Mar 13 '17 at 17:55
5
When you send a GET request to the database root, as per OrangeDog's answer, i.e.: GET http://couchdb.server.com/mydatabase
you will get a JSON back, looking similar to the following:
{
"db_name":"mydatabase",
"update_seq":"2786-g1AAAAFreJzLYWBg4MhgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUoxJTIkyf___z8riYGB0RuPuiQFIJlkD1Naik-pA0hpPExpDj6lCSCl9TClwXiU5rEASYYGIAVUPR-sPJqg8gUQ5fvBygMIKj8AUX4frDyOoPIHEOUQt0dlAQB32XIg",
"sizes":{
"file":13407816,
"external":3760750,
"active":4059261
},
"purge_seq":0,
"other": {
"data_size":3760750
},
"doc_del_count":0,
"doc_count":2786,
"disk_size":13407816,
"disk_format_version":6,
"data_size":4059261,
"compact_running":false,
"instance_start_time":"0"
}
The field doc_count
is a count of all documents in the database. Bear in mind that the count includes design documents, that might not be what you are looking for.
There are other options, like creating a view with a default reduce function _count
that would allow you to get a single number representing a number of documents generated in that view, that could get around the issue of counting in design documents.

seb
- 808
- 1
- 9
- 17