0

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 ?

Kim Yu
  • 205
  • 2
  • 9
  • 1
    You can't do auto-increment in CouchDB, nor should you really try to due to it's potentially distributed nature. If you are wanting to build friendly URLs, you could generate "slugs" based on the blog title. Also, there's an existing blog demo called [Sofa](https://github.com/jchris/sofa) that is probably worth checking out. – Dominic Barnes Mar 25 '12 at 14:34
  • I cant't use a blog title to create friendly urls because i expected many that same titles of post/pages .. so i will need adding some number to it - so i back to my first question :) – Kim Yu Mar 25 '12 at 14:47

1 Answers1

1

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.

anvarik
  • 6,417
  • 5
  • 39
  • 53