Reputation: 6655
I have a site where I have documents that are around 1MB in size. To avoid any kind of conceptual joins I have put all related data in a single document.
Now I often need to fetch only one or two attributes of a document. Each document has over 10 attributes many of which are pretty large. I can not go on writing views for every single combination of the attributes.
How should I do it ? The only way I see is creating views on the fly and then using those views. OR is there any better method ?
Upvotes: 1
Views: 186
Reputation: 2616
http://wiki.apache.org/couchdb/Document_Update_Handlers
While it seems strange to call a update feature, couch allows you to return information from the document without updating it. See the xml example.
Here might be an example you could extend:
Add jsonpath to your ddoc, ( https://github.com/s3u/JSONPath)
function(doc, req) { var jsonpath = require('jsonpath'); var path = req.query.path; var target = jsonpath(doc, path); var json = JSON.stringify(target); var resp = { 'headers' : { 'Content-Type' : 'application/json' }, 'body' : json }; return [doc, resp]; }
Upvotes: 2