CouchDB/PouchDB 视图中每个文档的密钥发射限制

Limit of key emission per document in a CouchDB/PouchDB view

我的数据库结构如下:

{_id: 'record/1', name: 'Record 1', labels: ['label/1', 'label/2', 'label/3'], created: '2015-03-01T00:00:00.000Z'},
{_id: 'record/2', name: 'Record 2', labels: ['label/1', 'label/5', 'label/7', 'label/3'], created: '2015-03-06T00:00:00.000Z'},
{_id: 'record/3', name: 'Record 3', labels: ['label/2', 'label/3', 'label/4', 'label/5'], created: '2015-03-10T00:00:00.000Z'}

我有一个映射函数,它为每个文档发出多个键,即对于 'record/1',将发出这些键:

[2015,3,1] for record/1
["label/1"] for record/1
["label/1",[2015,3,1]] for record/1
["label/1","label/3"] for record/1
["label/1","label/3",[2015,3,1]] for record/1
["label/1","label/2"] for record/1
["label/1","label/2",[2015,3,1]] for record/1
["label/1","label/2","label/3"] for record/1
["label/1","label/2","label/3",[2015,3,1]] for record/1
["label/2"] for record/1
["label/2",[2015,3,1]] for record/1
["label/2","label/3"] for record/1
["label/2","label/3",[2015,3,1]] for record/1
["label/3"] for record/1
["label/3",[2015,3,1]] for record/1

看起来每个文档要发出很多复杂的键,但它支持我的查询要求:

  1. 查找在开始日期结束日期之间创建的记录
    • {startkey: [2015, 3, 1], endkey: [2015, 3, 9]}
  2. 查找应用了多个标签的记录,即'label/1'和'label/3'
    • {key: ['label/1', 'label/3']}
  3. 查找在开始日期结束日期之间创建并应用了多个标签[=43=的记录]
    • {startkey: ['label/1', 'label/3', [2015, 3, 1]], endkey: ['label/1', 'label/3', [2015, 3, 9]]}

问题:使用这种方法,我会在 CouchDB 或 PouchDB 中遇到任何限制或性能问题吗?

不,这看起来可能是在 PouchDB 中使用 map/reduce 索引的最有效方式。 :) 将所有内容都放入一个大索引中,一定会让您在视图构建过程中获得最佳性能。