Kim Yu
Kim Yu

Reputation: 235

Autoincrement in couchdb

I'm trying to write a web application using nodejs and couchdb. In couch i store content of my seperates page. What is my problem..

i would have a nice urls like this:

http://mypage.com/content/1/blabla-detail.html
http://mypage.com/content/2/blabla-detail.html
http://mypage.com/content/5/blabla-detail.html
http://mypage.com/content/n/blabla-detail.html

generally

http://mypage.com/content/{OID}/blabla-detail.html

so i need some kind like a autoincrement in couchdb. Offcourse i can use a _id - it is a unique in couchdb but ... uuid in couch is long hash ... i don't want this long hash in my urls :( i looking some unique but short values.

I just thinking about creating view to get count of all rows in documents but ... what in case when at this same time few user will save a new element. There will be problem - couchdb has not a transaction.

I'm stuck.

Can anyone help me to resolve this problem ?

Upvotes: 0

Views: 453

Answers (1)

anvarik
anvarik

Reputation: 6487

I am not sure if I got your question. So you have a CDB database that you store your separate pages of your blog as documents. Then you want to reach those documents via their _id's which are stored as unique hashes. Am I right? Since those hashes are dirty, you want to give them unique, but prettier numbers.

If so, I can recommend you to use Ektorp API. Here, you connect to the database via CouchDBConnector and then you can call all of your documents via the method getAllDocIds as a List<String>. Then simply you can write REST services, and can give better ids. Hope it helps.

Upvotes: 1

Related Questions