Jason
Jason

Reputation: 15931

Retrieving documents from couchbase view using REST API

I'm starting with couchbase 3.01 and I have a question about views. The documentation I read said you should not include the full document in the index, as it will have a negative impact on both storage and performance. Now I've created a mapping function and I'm emitting null for the document

e.g.

function(doc, meta) {
  if (doc.entity && doc.entity == 'desert') {
    emit(doc.type, null);
  }
}

This should create an index for my various types of deserts (cookie, ice cream, cake). When I save the view, and click the 'Show Results' button in the admin console, I see all of the keys with the associated value of null.

If I change my mapping function to include the document e.g.

function(doc, meta) {
  if (doc.entity && doc.entity == 'desert') {
    emit(doc.type, doc);
  }
}

I get the results I expect, but, I'm concerned that this is an anti-pattern. It seems like there used to be a querystring parameter include_docs which would dereference the document, but it doesn't appear in the documentation. Should I include the full document in the indexes I generate? If not, how do I retrieve the document by key?

Upvotes: 1

Views: 1990

Answers (1)

user1697575
user1697575

Reputation: 2848

The pattern is to have a view defined without full DOC included. Then you can use Couchbase client library specific for your application platform (e.g. Java, Python, Node.js, .Net, etc.) to access documents from your view by setting flag include_docs(when needed).

The REST API should not be used to read or write data to the server. Data operations, such as set and get for example, are handled by Couchbase SDKs.

Upvotes: 2

Related Questions