Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

couchdb how to list all users on db?

Tags:

curl

couchdb

I'm trying to determine what users have been created.

is there a curl command in couch to list all existing couchdb users?

if so what is it is that curl call?

like image 862
Kristian Avatar asked Nov 11 '12 16:11

Kristian


People also ask

Does CouchDB have collections?

Couchdb does not have the concept of collections. However, you can achieve similar results using type identifiers on your documents in conjunction with Couchdb views. When you save a document in Couchdb add a field that specifies the type.

What is CouchDB and list out its features?

CouchDB is a document storage NoSQL database. It provides the facility of storing documents with unique names, and it also provides an API called RESTful HTTP API for reading and updating (add, edit, delete) database documents. In CouchDB, documents are the primary unit of data and they also include metadata.

Which of the following built in view returns a listing of all documents in the Apache CouchDB database?

2. /{db}/_all_docs. Executes the built-in _all_docs view, returning all of the documents in the database.


2 Answers

curl gets all users as documents, grep extracts documents _id, sed strips org.couchdb.user: prefix and sort removes duplicates that comes from view result:

curl -s http://localhost:5984/_users/_all_docs | grep -o 'org.couchdb.user:[[:alnum:]]\+' | sed -n -e 's/org.couchdb.user:\(.*\)/\1/p' | sort -u

Note, that since 1.2.0 release if you had fixed Admin Party on server, you need to pass CouchDB admin credentials to make such requests for _users database.

like image 191
Kxepal Avatar answered Nov 02 '22 23:11

Kxepal


Use _all_docs, the following command lists all docs info of a specific database, just specify database name then you are done:

curl -X GET http://localhost:5984/<db_name>/_all_docs

Then replace <db_name> with _users, and use port 5986 since _users is a system table under port 5986:

curl -X GET http://localhost:5986/_users/_all_docs
like image 22
coderz Avatar answered Nov 02 '22 23:11

coderz