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

时间:2015-03-09 08:43:59

标签: couchdb pouchdb

我有一个数据库结构,如:

{_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'和'标签/ 3'
    • {key: ['label/1', 'label/3']}
  3. 查找在开始日期结束日期之间创建的记录,并应用多个标签
    • {startkey: ['label/1', 'label/3', [2015, 3, 1]], endkey: ['label/1', 'label/3', [2015, 3, 9]]}
  4. 问题:使用这种方法,我是否会遇到CouchDB或PouchDB中的任何限制或性能问题?

1 个答案:

答案 0 :(得分:2)

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