couchdbcouchappcouchdb-futon

Retrieving multiple attachments with multiple documents


I'm building an app right now using couchdb, spring, and angularjs. On my UI I'm creating a document with attachments inside it (image) and I'm submitting them to my server which validates and then submits to the database. When I want to retrieve these documents to display them on the UI, first I call my view

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

I'm returning null as the second parameter because I read somewhere that it was better performance to not return the doc and to use includedocument = true request parameter. Once I have my list of documents, their attachments are only stubs and I need the data. So I make a new request for each document to get the document with the attachment. This feels very redundant and I feel like I'm doing it wrong. If this is the way I must do it, is there a better way performance wise? I'm thinking that since I have to retrieve the document again anyway to get the attachment, maybe I should leave out the includedocuments = true on my initial request since really all I need is the ID. What do you guys think?


Solution

  • In my opinion, you need to set includedocuments = false. After you get all id's of documents your need, just request them. I think it's more universal way if you'll have some changes in logic in View. For example, you will need to sort docs by the type, and you will need to create more different views