pouchdb 没有通过 query() 获取附件

pouchdb not getting attachments with query()

我有一个名为 _design/templates 的设计视图(获取所有具有特定类型的文档):

function (doc) {
  if(doc.type == "template")
    emit(doc._id, doc);
}

然后我通过查询获取视图:

db.query('templates',{ 
    include_docs: true,
    attachments: true
})
.then(function (result) {
    console.log(JSON.stringify(result));
});

结果显示了附件,但没有给我 data 属性以及图像的实际 base64 数据。

"_attachments":{
  "page_2.png":{
    "content_type":"image/png",
    "revpos":3,
    "digest":"md5-UHICp3Zi90ZVNMzyTUqRkQ==",
    "length":1917411,
    "stub":true
  },
  "page_1.png":{
    "content_type":"image/png",
    "revpos":2,
    "digest":"md5-GTXsZlsMa+NwZQDjJNMVAw==",
    "length":492139,
    "stub":true
  }
}

有人知道为什么会这样吗?

@AlexisCôté 帮我解决了这个问题。因为我已经在用 include_docs 检索文档,所以我改变了我的看法:

这个:

function (doc) {
  if(doc.type == "template")
    emit(doc._id, doc);
}

对此:

function (doc) {
  if(doc.type == "template")
    emit(doc._id);
}