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 Call | object.add(key, expiry, flags, value) | ||
| Asynchronous | no | ||
| Description | Add a value with the specified key that does not already exist. Will fail if the key/value pair already exist. | ||
| Returns | object (
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.
membase.add("someKey", 0, 0, someObject)Unlike Section 3.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:
membase.set("someKey",0,0,"astring") membase.add("someKey",0,0,"astring")