【发布时间】:2019-01-25 21:17:07
【问题描述】:
我想获取所有 id 与正则表达式匹配的文档。
例如,我有以下文档 ID:
p0
p0/e0
p1
p1/e0
我怎样才能只得到 p0 和 p1 ?正则表达式是 /^p[0-9]+$/
目前我可以执行两个请求,但我只想使用一个:
This.db.allDocs({
include_docs: false
}).then(function(result){
// Find all ids matching /^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);
}
}
// Get 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);
});
});
【问题讨论】:
-
你使用什么样的正则表达式?你能提供更多信息
标签: javascript pouchdb