Is there a way to retrieve all documents with IDs that match a specific regex expression?
Let's say we have the following document IDs:
p0
p0/e0
p1
p1/e0
How do we only retrieve p0 and p1? Using the regex /^p[0-9]+$/.
Currently, it takes two requests to achieve this. Is there a method to accomplish this with just one request?
This.db.allDocs({
include_docs: false
}).then(function(result){
// Find all IDs that match /^p[0-9]+$/
var iDoc = result.rows.length;
while(iDoc--){
if(result.rows[iDoc].id.match(/^p[0-9]+$/)){
projectsIds.push(result.rows[iDoc].id);
}
}
// Retrieve all documents with IDs matching /^p[0-9]+$/
This.db.allDocs({
include_docs: true,
keys: projectsIds
}).then(function(result) {
var iProject = result.rows.length;
var docs = [];
while (iProject--) {
docs[iProject] = result.rows[iProject].doc;
}
projects.resolve(docs);
});
});