loopback-connector-couchdb
What
A connector is used to connect Loopback models to a storage, and in this case, a CouchDB DB. See the official doc for Connecting models to data sources.
How to
Config
Example:
{
"lorem": {
"name": "cache",
"connector": "couchdb",
"url": "${couchdbUrl}",
"database": "lorem",
"designDocs": {}
}
}
Install design docs
The designDocs
that you put in the datasource config can be installed with autoupdate()
or automigrate()
. Example:
{
"lorem": {
...
"designDocs": {
"find": {
"views": {
"byName": {
"map": "function(doc) { if (doc.name) emit(doc.name, null); }"
}
}
}
}
}
}
Use a view
Example:
connector.connect().call('viewAsync', 'find', 'byName', { keys: ['Charlie'] }).then((res) => {
res.should.be.Object();
res.should.have.property('rows').which.is.Array().with.length(1);
});
See the tests for more examples.