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

Questions about the Couchbase client APIs

2 replies [Last post]
  • Login or register to post comments
Wed, 12/19/2012 - 17:45
cyang
Offline
Joined: 12/19/2012
Groups: None
  1. To create a document, is there a single client API that tells us the object already exists without creating the object or the need of making a get() call prior to the actual create call?  Neither the set() nor the add() method seem to give me that.
  2. To update an existing document, is the replace() method a good choice?

Thanks,

Connie

Top
  • Login or register to post comments
Wed, 12/19/2012 - 20:21
scalabl3
Offline
Joined: 07/18/2012
Groups:

1. Interesting question, traditionally/typically that's the purpose of the get(), get's are extremely fast, if the key doesn't exist, it is a nearly instant return since all keys(metadata) are kept in memory.

The set() method *always* sets, overwriting what's there without error, which isn't what you want in this case.

get() and add() can be used sequentially, but if you know you want to create, simply using add() works exactly how you want it to and you don't need the get() first because it will fail immediately (nearly instantly) if it exists.

2. Replace is definitely a good choice if logically the Document should already exist (i.e. a user updating their password). It raises an error if it doesn't exist already. It's the complement to add().

Your question prompted me to ask the SDK team to potentially add a method called check() which returns true/false if the key exists or not, but this is a very niche and rare need to not actually get the value, just existence only. If you are following it with an add() then you don't really need a check(), just handle the exception.

Hope this was helpful!

__________________

@scalabl3
Technical Evangelist
Couchbase Inc.
 

Top
  • Login or register to post comments
Wed, 12/19/2012 - 20:22
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

1. To "create" a document you have two possible operations:

- set : will create if document does not exist, will update if the document already exists (no warning message)
- add : will fail if the document already exist

You can find information about these operations
http://www.couchbase.com/docs/couchbase-devguide-2.0/cb-store-operations...

2. To replace/update a document you have 2 options:
- set : see above
- update : will faill if the document does not exist

You can find more information about "updating" a document here, since you have multiple options:
http://www.couchbase.com/docs/couchbase-devguide-2.0/cb-update-operation...

Regards
Tug

__________________

Tug
@tgrall

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