【发布时间】:2015-05-24 23:55:26
【问题描述】:
我有一个非常简单的数据库,其中包含一些存储在 Cloudant 中的数据模式。
{
"_id": "units_modal_the_oaks_preliminary",
"_rev": "1-b541013bc008680b706ea01969dedb7a",
"type": "units_modal",
"label": "Preliminary Modal",
"notes": "Notes here...",
"project": "the_oaks",
"data": [...]
}
我将 Cloudant 与 PouchDB 连接起来。我的目标只是让这个数据库准备好被除数据之外的所有字段查询。
我使用 PouchDB-Find 来查询数据。我花了一整天的时间在文档上创建设计文档和视图,但我不知道如何正确地做到这一点。所有文件都建议使用 map 函数和 reduce 函数。我尝试了各种手动设计地图功能的方法,但是当我运行查询时
remoteDb.find({
selector:{type:"units_modal"}
})
我收到“no_usable_index”错误。我只能使用 PouchDB-find 提供的方法来创建索引 & 然后我可以得到我想要的结果:
remoteDb.createIndex({
index: {
fields: ['type', 'project','label','notes']
}
})
我查看了设计文档。这是我所拥有的(我已将 id 和视图重命名):
{
"_id": "_design/project",
"_rev": "8-c7e2b7c0e1dbaff8e5641a4f06075e14",
"language": "query",
"views": {
"units_modal": {
"map": {
"fields": {
"type": "asc",
"project": "asc",
"label": "asc",
"notes": "asc"
}
},
"reduce": "_count",
"options": {
"def": {
"fields": [
"type",
"project",
"label",
"notes"
]
},
"w": 2
}
}
}
}
所有这些都非常令人困惑。似乎除了地图功能外,我找不到任何东西来解释地图。这里的地图功能在哪里?关于 map.fields、views.options.def 和 views.options.w 的文档和说明在哪里?
有人可以提出一种简单的方法来设计可以轻松查询有关特定类型文档的所有字段的视图吗?
谁能推荐一个地方,让我可以得到更多关于 map.fields、view.options 和所有这些关于 CouchDB 的小东西的解释?
有没有简单的“if(type=='some type') indexAll();”解决办法?
非常感谢!
【问题讨论】: