Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

Using short ID generator and duplicates

6 replies [Last post]
  • Login or register to post comments
Fri, 11/02/2012 - 00:20
Idan
Offline
Joined: 05/18/2012
Groups: None

I want to use friendly URLs in my web application. I prefer generating a short unique ID instead of a GUID. From what I know if I store data using the Add command and the key is duplicated, it will return an error. So my question is whether its safe to use my own unique short ID generator and handle duplicate key exception in the application layer in order to insert the document again with a different key until it's accepted.

I know that the chances to get duplicated, even with a short ID (like the one used by bitly) are rather small, but if If duplicated can't be inserted I have no problem using it, because I prefer a shorter ID than the GUID.

Any suggestions,

Top
  • Login or register to post comments
Fri, 11/02/2012 - 07:40
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello Idan,

A quite simple approach will be to use Counter ID, with the increment command. Is that compliant with your use case?

You create a numeric item and you just increment it, and use it in your key. Like that you are sure that it is unique and small. It is more or less the same thing that using a Sequence in RDBMS engine.

Is that Ok with your business requirements ?

You can find more information here:
http://couchbasemodels.com/patterns/counter_id

Also which language (SDK) do you use for your application it will help to find a good approach.

Regards
Tug

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Fri, 11/02/2012 - 07:48
Idan
Offline
Joined: 05/18/2012
Groups: None

So I can use it the same as like in RDBMS (only numbers) with no problems with the cluster or performance?

Furthermore, is it BigInt?

I use ASP.NET

Top
  • Login or register to post comments
Fri, 11/02/2012 - 08:12
tgrall
Offline
Joined: 09/05/2012
Groups: None

Idan,

Yes you can, and it is really very fast because when you call the increment methods it done (like any of the Couchbase CRUD) operation using the Memcached protocol.

So generating the ID/Incrementing the sequence will have no impact to your application, even in a large cluster, thanks to the vBucket architecture.

You can find the documentation about the increment method for Microsoft ASP here:
http://www.couchbase.com/docs/couchbase-sdk-net-1.1/couchbase-sdk-net-up...

Regards
Tug

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Mon, 11/05/2012 - 16:25
donald
Offline
Joined: 11/05/2012
Groups: None

Do you have some idea, how is it possible generate increment ID in nodejs ? I use couchnode ..

Top
  • Login or register to post comments
Mon, 11/05/2012 - 17:59
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello Donald

The increment/decrement -incr()/decr()- functions have just been added to the Couchnode API.

You can see some tests that are using the functions here:
- https://github.com/couchbase/couchnode/blob/master/tests/09-incr-decr.js

Be sure you are using the latest libcouchbase library.

Regards
Tug

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Thu, 11/08/2012 - 15:30
donald
Offline
Joined: 11/05/2012
Groups: None

Tug, sorry, it was my mistake.

Thank you very much !

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker