I have an CouchDB database named t-customers
. Using Fauxton I've created the following view t-customers/_design/t-cust-design/_view/by-custdes
. Here is the map function:
function (doc) {
var custname = doc.CUSTNAME;
if(custname != undefined && custname.length != undefined && custname.length != ''){
for(var i = 0; i < custname.length - 1; i++)
for(var j = i + 1; j < custname.length + 1; j++)
emit(custname.substring(i, j),doc._id);
}
}
The view will contain all available sub-strings for custdes (e.g. custdes=abc -> a, ab, abc, bc) as key and doc._id as its value.
After the view is created I can query it with the following http requests:
http://127:0.0.1:5984/t-customers/_design/t-cust-design/_view/by-custdes?key="ab"
http://127:0.0.1:5984/t-customers/_design/t-cust-design/_view/by-custdes?key="abc"
It works as fast as lightning although my view has about 1.500.000 documents indexed.
First of all: I've noticed that the PouchBD syncs only the t-customers database and not it's view. Why? To make the view avaliable in PouchDB it requires for me to run the following command which takes up to 20 minutes to complete:
t-customers.query("t-cust-design/by-custdes").then(...).catch(...);
Only and only then I can see the view at IndexedDB in Chrome.
Second of all: What is the way to look up a doc in PouchDB view t-cust-design/by-custdes
without triggering the whole map/reduce process every time I want to find the ab
key? As I mentioned I can query the CouchDB _design/t-cust-design/_view/by-custdes
view with http request and it works fast, but I'm unable to do the equivalent action using PouchDB API.
I've read tons of documentation but I'm still confused about it...