Additionally, this library provides enhanced support for bulk operations. The the native couchbase
module only provides batch operation support for key lookups (via Bucket.prototype.getMulti()
). The couchbase-promises
module provides a extra methods on the Bucket
class for performing batch operations. See the API documentation for more information.
The current version supports Couchbase Node.js SDK version 2.2.5.
Usage is almost exactly the same as the native SDK, but with the added ability to use Promises instead of callbacks.
A user repository module with a simple lookup...
-
Bucket.prototype.appendMultiAsync(docs, options)
:
Appends a value for each given key.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
docs
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
fragment
: (required) the value to append.
-
options
: (optional) object that contains the options used for append. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.counterMultiAsync(docs [, defaultOptions])
:
Increments counter entries for each key.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
docs
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
delta
: (required) the value to append.
-
options
: (optional) object that contains the options used for counter. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.getAndLockMultiAsync(keys [, defaultOptions])
Gets the document for each key, and adds an exclusive lock for each entry.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys you wish to get and lock.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for getAndLock. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.getAndTouchMultiAsync(docs [, defaultOptions])
Gets the document for each key, sets their TTL value.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
docs
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
expiry
: (required) the TTL duration in seconds.
-
options
: (optional) object that contains the options used for getAndTouch. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.getReplicaMultiAsync(keys [, defaultOptions])
:
Gets documents for the specified keys from replica nodes.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys you wish to get and lock.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for getReplica. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.insertMultiAsync(docs [, defaultOptions])
:
Inserts multiple documents into the bucket.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
docs
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
value
: (required) the value of the document.
-
options
: (optional) object that contains the options used for insert. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.listAppendMultiAsync(keys [, defaultOptions])
:
Appends an item to each list entry.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
value
: (required) the value to append.
-
options
: (optional) object that contains the options used for listAppend. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.listGetMultiAsync(keys [, defaultOptions])
:
Gets multiple list entries.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
index
: (required) the index of the item in the list to retrieve.
-
options
: (optional) object that contains the options used for listGet. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.listPrependMultiAsync(keys [, defaultOptions])
:
Prepends an item to each list.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
value
: (required) the value to prepend.
-
options
: (optional) object that contains the options used for listPrepend. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.listRemoveMultiAsync(keys [, defaultOptions])
:
Removes an item from each list.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
index
: (required) the index of the item to remove from the list.
-
options
: (optional) object that contains the options used for listRemove. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.listSetMultiAsync(keys [, defaultOptions])
:
Sets an item at a specific index for each list.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
index
: (required) the index of the list entry you are setting.
-
value
: (required) the value to set in the list.
-
options
: (optional) object that contains the options used for listSet. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.listSizeMultiAsync(keys [, defaultOptions])
:
Gets the size of each list.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys for lists to which you want to get the size.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for listSize. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.mapAddMultiAsync(keys [, defaultOptions])
:
Adds an entry to each map.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
path
: (required) the key within the map.
-
value
: (required) the value to store in the map.
-
options
: (optional) object that contains the options used for mapAdd. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.mapGetMultiAsync(keys [, defaultOptions])
:
Gets a value from each map given a path.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
path
: (required) the key within the map you wish to fetch.
-
options
: (optional) object that contains the options used for mapGet. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.mapRemoveMultiAsync(keys [, defaultOptions])
:
Removes an item given a path for each map.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
path
: (required) the key within the map you wish to remove.
-
options
: (optional) object that contains the options used for mapRemove. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.mapSizeMultiAsync(keys [, defaultOptions])
:
Gets the size of each map.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys for maps to which you want to get the size.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for mapSize. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.prependMultiAsync(keys [, defaultOptions])
:
Prepends a value to each document.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
fragment
: (required) the value to prepend.
-
options
: (optional) object that contains the options used for prepend. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.queuePopMultiAsync(keys [, defaultOptions])
:
Pops the next item off of each queue.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys for queues to which you want to get the size.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for queuePop. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.queuePushMultiAsync(keys [, defaultOptions])
:
Pushes an item to the end of each queue.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
value
: (required) the value to push to the queue.
-
options
: (optional) object that contains the options used for queuePush. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.queueSizeMultiAsync(keys [, defaultOptions])
:
Gets the size of each queue.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys for queues to which you want to get the size.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for queueSize. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.removeMultiAsync(keys [, defaultOptions])
:
Removes multiple documents in the bucket.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys you wish to remove.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for remove. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.replaceMultiAsync(docs [, defaultOptions])
:
Replaces multiple documents in the bucket.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
docs
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase you wish to replace. Each value is an object with the following keys:
-
value
: (required) the replacement value.
-
options
: (optional) object that contains the options used for replace. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.setAddMultiAsync(keys [, defaultOptions])
:
Adds an item to each set.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
value
: (required) the value to add o the set.
-
options
: (optional) object that contains the options used for setAdd. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.setExistsMultiAsync(keys [, defaultOptions])
:
Determines whether or not an item exists in each set.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
value
: (required) the value to which you are validating the existence.
-
options
: (optional) object that contains the options used for setExists. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.setRemoveMultiAsync(keys [, defaultOptions]s)
:
Removes an item from each set.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
value
: (required) the value you wish to remove from the set.
-
options
: (optional) object that contains the options used for setRemove. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.setSizeMultiAsync(keys [, defaultOptions])
:
Gets the size of each set.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) an array or Set
of keys for sets to which you want to get the size.
Alternatively keys
can be a Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
options
: (optional) object that contains the options used for setSize. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.touchMultiAsync(keys [, defaultOptions])
:
Sets the TTL expiration for each document.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
expiry
: (required) the TTL duration in seconds.
-
options
: (optional) object that contains the options used for touch. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.unlockMultiAsync(keys [, defaultOptions])
:
Unlocks each document if the provided corresponding CAS values match the current.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
keys
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase. Each value is an object with the following keys:
-
cas
: (required) the CAS value that was returned when the value was locked.
-
options
: (optional) object that contains the options used for unlock. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
-
Bucket.prototype.upsertMultiAsync(docs [, defaultOptions])
:
Upserts multiple documents to the bucket. This method will create individual upsert operations for each key using Promisea.all()
.
Returns a Promise
that resolves with a Summary
object. This Promise
will always be fulfilled. Any errors that occur will be specified in the resolved Summary
.
Parameters include:
-
docs
: (required) object or Map
where each key corresponds to the key used to store the document in Couchbase you wish to upsert. Each value is an object with the following keys:
-
value
: (required) the contents of the document to be upserted.
-
options
: (optional) object that contains the options used for upsert. If this key is absent, options provided by defaultOptions
will be used. If you provide this key as part of a docs
entry, but set it to undefined
or null
no options will be used on the insert, and regardless of whether or not defaultOptions
was provided.
-
defaultOptions
: (optional) default options for each operation.
Contains a summary of a bulk operation. Keys include: