开发者

Couchdb: Show _attachments

Just getting a feel for CouchDB and hitting a few misunderstanding.

I can list the records from a view with (thanks to a previous responder)

开发者_如何学Python
http://mysite.iriscouch.com/mydb/_design/_view/myview

I have amended my view to include _attachments, but that does not appear to be showing the _attachments, which are jpeg files.

map
function(doc) {
  if(doc.SignMark && doc.Details) {
    emit(doc.SignMark, doc.Details, doc._attachments);
  }
}

I have obviously missed some simple concept

Thanks - mcl


From within a view you cannot access the attachments themselves. You can only the metadata which is stored in the doc._attachments.

So depending on your requirements, you will have to access the actual attachment with a second request of the format /db/doc-id/attachment-name.jpg

or, if you are rendering to html, just construct an image tag with the src='/db/doc-id/attachment-name.jpg'


Emit always takes two parameters: key and value. Each can be an object. So this would work:

function(doc) {
  if(doc.SignMark && doc.Details) {
    emit(doc.SignMark, [doc.Details, doc._attachments]);
 }
}

But you can construct arbitrary keys and values to emit, and you can also emit multiple or no values at all for each document.

The excellent CouchDB Book helped me a lot! This is the relevant chapter for views: http://guide.couchdb.org/draft/views.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜