How to Check if the db exists in couchdb or not?

I am creating database in couchdb for every user who is registered in my website. I am using couch per user concept here. How can I verify if the database already exists before user registration? couchdb version is 2.2.0 .

Upvotes: 1

Views: 1084

Answers (1)

Juanjo Rodriguez
Juanjo Rodriguez

Reputation: 2131

If your users are registered in CouchDB, you can enable the couch per user functionality. In this case, user database is named with the following rule userdb-{hex encoded username} where {hex encoded username} is the hex string of the utf-8 representation of the user name.

You could evaluate the db name from de user name and then check the existence with this API operation:

HEAD /userdb-{hex encoded username}

If the users are managed by your application and are not defined in couch, you can just check the database existence using your db naming rule

Upvotes: 1

Related Questions