> Hi, > > why do you say it is a 'mistake' to emit doc from a view? > I do have views that get some param and return the resulting doc(s). > E.g.: > > |||"|map|":|"function(doc) {if(doc.startDate && !doc.disabled) > {emit(doc.startDate, doc);}}"|||| >
Perhaps it's more correct to say "unnecessary". You can always get the associated documents from the results of a view using the include_docs flag. I personally don't know if this has advantages in terms of space, but I do believe emitting a document will result in it being saved additionally to disk in the view results. For your case, you can simply do emit(doc.startDate, null) and still get the behavior you need. > > > > Is there more effective way? > Thanks. > ------------------------------------------------------------------------ > *With best regards,* > Kiril Stankov > > On 2/1/2015 4:30 PM, Jonas Weber wrote: > >> It is a common "mistake" to emit a document or document id from a view; >> if it is not mirroring your _id, please ignore my last comment. >> >> On February 1, 2015, Ayhan Kesenci <a.kesenc...@googlemail.com> wrote: >> >> what do you mean, with id_str ?, but it is in the same datafile ! >>> >>> 2015-02-01 14:59 GMT+01:00 Jonas Weber <m...@jonasw.de <mailto: >>> m...@jonasw.de>>: >>> >>> Because emit() takes two parameters, one is the key, one is the >>> value. >>> >>> However, you can emit arrays as key and/or as value, and they will be >>> sorted as expected: >>> >>> emit([doc.user.friends_count, doc.user.followers_count], doc.id_str); >>> >>> Or something similar... >>> >>> By the way, what is id_str? If you want to use the doc when >>> requesting the >>> view, it is better to request the document directly with >>> ?include_docs=true, saving you a roundtrip to the server. >>> >>> >>> On February 1, 2015, Ayhan Kesenci <a.kesenc...@googlemail.com >>> <mailto:a.kesenc...@googlemail.com>> wrote: >>> >>> Why it is not possible to create a view like this >>> >>> function(doc) { >>> emit(doc.user.friends_count,doc.user.followers_count,doc.id_str); >>> } >>> >>> >>> ?? >>> >>> >>> >