使用 PouchDB 在 Ionic2 应用程序中访问 map/reduce 的结果
Accessing result of map/reduce within Ionic2 app using PouchDB
我在与我在 AWS 上的 CouchDB 同步的 Ionic 2 应用程序上使用 PouchDB。
我已经在 futon 中创建了一个设计文档,如果我转到 http://my-ip-address:5984/wardround_jobs/_design/teams/_view/teams 效果很好 - 我可以看到我设计中使用的 map/reduce 输出的 JSON .
我现在正在尝试弄清楚如何在我的应用程序中访问它。
我从这个开始 - 它给了我所有文件:
return new Promise(resolve => {
this.db.allDocs({
include_docs: true
}).then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
然后我可以修改它以取回一份特定文件:
return new Promise(resolve => {
this.db.get('0448071807c0f37f53e06aab54034a42').then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
但是,如果我尝试使用此代码取回我的设计视图,则会返回一个错误:
return new Promise(resolve => {
this.db.get('_design/teams/_view/teams').then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
错误是:
CustomPouchError {
status: 404,
name: "not_found",
message: "missing",
error: true,
reason: "missing"
}
如何在我的应用程序中访问 map/reduce 的结果?
编辑 - 在 Alexis 的帮助下,我完成了这项工作...
return new Promise(resolve => {
this.db.get('teams/teams').then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
要从任何 map/reduce 设计文档中获取结果,您需要使用 query() 函数。
我在与我在 AWS 上的 CouchDB 同步的 Ionic 2 应用程序上使用 PouchDB。
我已经在 futon 中创建了一个设计文档,如果我转到 http://my-ip-address:5984/wardround_jobs/_design/teams/_view/teams 效果很好 - 我可以看到我设计中使用的 map/reduce 输出的 JSON .
我现在正在尝试弄清楚如何在我的应用程序中访问它。
我从这个开始 - 它给了我所有文件:
return new Promise(resolve => {
this.db.allDocs({
include_docs: true
}).then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
然后我可以修改它以取回一份特定文件:
return new Promise(resolve => {
this.db.get('0448071807c0f37f53e06aab54034a42').then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
但是,如果我尝试使用此代码取回我的设计视图,则会返回一个错误:
return new Promise(resolve => {
this.db.get('_design/teams/_view/teams').then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
错误是:
CustomPouchError {
status: 404,
name: "not_found",
message: "missing",
error: true,
reason: "missing"
}
如何在我的应用程序中访问 map/reduce 的结果?
编辑 - 在 Alexis 的帮助下,我完成了这项工作...
return new Promise(resolve => {
this.db.get('teams/teams').then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
});
要从任何 map/reduce 设计文档中获取结果,您需要使用 query() 函数。