var cbadmin = require('couchbase-admin');
var bucket = new cbadmin.Bucket({
conn: 'localhost:8091',
bucket: 'default',
timeout: 10 * 60 * 1000,
logger: {
debug: console.log,
info: console.log,
warn: console.warn,
error: console.error,
},
admin_design_document
});
var comparison_report = cbadmin.DesignDocuments.compare(src_ddoc, dst_ddoc);
bucket.createView('ddoc_test', 'myview', {
map: 'function (meta, doc) { emit(meta.id, null); }'
});Creates a new Couchbase bucket connection based on the provided paramenters.
Supported paramenters:
conn: (required) a connection string, for example,localhost:8091bucket: (required) the bucket to connect totimeout: (optional) operation timeout in miliseconds, defaults to 10 minuteslogger: (optional) a logger instance with the methodsdebug,info,warnanderror. No other methods are used by the library.admin_design_document: (optional) this is the design document name used bycouchbase-adminto install views required for certain operations. Note that you can provide a development design document name (prefixdev_) but that is not recommended. Defaults tocbadmin.
Full options list example:
var bucket = new cbadmin.Bucket({
conn: 'localhost:8091',
bucket: 'default',
timeout: 10 * 60 * 1000,
logger: {
debug: console.log,
info: console.log,
warn: console.warn,
error: console.error,
},
admin_design_document: `cbadmin`
});Call this to terminate the connection.
Resolves with an Object containing all design documents of the bucket.
Installs a new design document named name using the definition provided by data. The data must be with the same structure as that obtained from a Bucket.getDesignDocuments.
Development Design Documents
If the design document is prefixed with dev_, which is Couchbase's definition of a development design document then this method only performs the following
- Create the design document
- If it contains at leat one view then a query on the view is performed in order to force indexing
Production Design Documents
If the design document is not prefixed with dev_ then this method will
- Create a development design document first by prefixing
namewithdev_ - If
datacontains at least one view then a query on the first view is executed in order to force indexing the whole design document - Publish the development design document to production
- Remove the development design document
design_doc_nameStringview_nameStringview_codeObject
Creates a new view on the design document provided. If the view already exists and has a different view_code then the Promise rejects with an Error instance. If the view already exists and is the same then nothing is done and the Promise resolves.
The view_code is something like
var view_code = {
map: 'function (meta, doc) { emit(meta.id, doc); }',
};Same as creatView except that it will overwrite a view if it is different. Does not upgrade the view if it matches the one already installed.
Removes a view from a design document. Nothing is done if the view has already been removed from the design document.
The prefixes are a list of document key prefixes. If no prefix is passed then the view will return all documents in the bucket, otherwise it will return all documents matching at least one of the prefixes.
Same as Bucket.fetchAllMatching except that it will return all document keys which are not prefixed by any of the provided prefixes.
Used internally.
Used internally.
Run a query on a view and the call iterator for each element.
Available options (opts):
iterate : Boolean: Iftruethen it will query the view using ranged queries. This is only recommended for very large result sets (millions) or if the result set has enough data to result in a memory problem for the client. Defaults tofalse.
Performs a query on a view. This will also detect timeouts usually result of Couchbase still indexing the view and will retry the operation. Logs will inform about the operation progress.
Available options (opts):
order : StringPossible values aredescorasc. Defaults toasc.key : StringQuery for a specific key.from : StringUsed for range queries to mark the starting point of the range. Note that iffromis defined then it is assumed the view was already queried and therefor indexed. This means that the query will run on a potential stale index.limit : NumberThe max size of the result set.
Used internally.
Fetches a document from Couchbase. Includes a retry mechanism with exponential (base 2) timeouts.
Inserts a document in Couchbase. This will result in an error if the key already exists. Includes a retry mechanism with exponential (base 2) timeouts.
Inserts or updates a document in Couchbase. Includes a retry mechanism with exponential (base 2) timeouts.
Removes a document from Couchbase. This will result in an error if the key already exists.
The return value contains a detailed report about the differences found. Please use the CLI in order to better understand the report before using this method.
Store data as a JSON file named file. Note that a JSON.stringify is used on data in order to generate the text data to write to the file.
Reads file as a JSON object and returns a Promise which resolves to that object. Note that a JSON.parse is used on the text data read from file.