停止 Cloudant 查询返回 _design 文档

Stop Cloudant queries returning _design document

我正在使用 NodeJS 模块查询 Cloudant 数据库,包括特定字段搜索和函数 db.list()。但是,我(大概是正确的)也被退回了所有设计文件。

有没有办法防止返回设计文档,即在使用列表时,没有运行检查_id 的特定查询,或测试数据库响应的每个项目?

我在文档中找不到执行此操作的方法,只是提到 _design 文档像任何其他文档一样被查询和更新,大概是列表中包含的原因。

谢谢

db.list() 函数正在访问 Cloudant 的 _all_docs 端点,例如

https://reader.cloudant.com/animaldb/_all_docs

这 return 键顺序的所有数据库文档(包括设计文档)。

由于所有设计文档的 ID 都以“_”字符开头,我们只能通过说

访问 "real" 文档

https://reader.cloudant.com/animaldb/_all_docs?startkey=%22a%22

即找到我所有以键以 "a".

开头的文件开头的文件

在 Node.js 中看起来像:

db.list({startkey:'a', include_docs:true}, function(err, data) { console.log(data); })

或者,您可以 create and index 这将允许您查询和 return 数据库的子集。设计文档不考虑用于索引目的,因此不会出现在结果集中。