Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Python 1.0
Community Wiki and Resources
Download Client Library
Python Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
4 Store Operations
Chapter Sections
Chapters

4.1. Add Operations

The add() method adds a value to the database with the specified key, but will fail if the key already exists in the database.

API Callobject.add(key, expiry, flags, value)
Asynchronousno
Description Add a value with the specified key that does not already exist. Will fail if the key/value pair already exist.
Returnsobject ( Binary object )
Arguments 
key Document ID used to identify the value
expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
flags Flags for storage options. Flags are ignored by the server byt preserved for use by the client.
object value Value to be stored

The add() method adds a value to the database using the specified key.

couchbase.add("someKey", 0, 0, someObject)

Unlike Section 4.2, “Set Operations” the operation can fail if the specified key already exists.

For example, the first operation in the example below may complete if the key does not already exist, but the second operation will always fail as the first operation will have set the key:

couchbase.set("someKey",0,0,"astring")
couchbase.add("someKey",0,0,"astring")