"But aren't temp views considered bad for performance." Almost certainly, yes. A temp view will read every document in your database every time it is executed. This is only tolerable for the very smallest databases.
Temp view is a mechanism for testing view code during development, there is no reasonable use case for temp views in production. B. On 14 March 2011 16:17, Kinley Dorji <[email protected]> wrote: > Hi Aroj, > > Unlike in SQL, CouchDB views cannot be filtered by value. They can be > only filtered by key for performance reasons as the key is where the > indexing action takes place. > > So the solution for you would be to have a view of this type: > > emit (doc.timestamp, {country:doc.country, city:doc.city, > hospital:doc.hospital, rooms:doc.rooms}); // this representing the > output of the map stage > > This would create a view that you could filter based on your start and > end time stamp keys for the desired period. > > The aggregation would take place in your code in the reduce stage, > which would manipulate the json that you created on the value side of > your key/value pair for a particular time stamp to get whatever > aggregation you need. > > Hope that helps. > > On Mon, Mar 14, 2011 at 10:02 PM, Aroj George <[email protected]> wrote: >> Thanks Kinley. But just emitting the timestamp does not solve the problem >> for us. >> >> We want to be able to emit something like, >> >> [India,Mahrashtra,Pune,timestamp] (where Pune is a city in state >> Maharashtra which is in country India) >> >> and then we would like to filter using the timestamp and group by location >> on say India as, >> >> *startkey=India,%,%,timestamp1 & endkey=India,%,%,timestamp2 & group_level = >> 1* >> >> This should give me all results grouped by location India, but filtered out >> between the two timestamps. >> >> But ofcourse there is no % filter possible it seems. >> >> A SQL equivalent would be, >> >> select * from table where timestamp > timestamp1 and timestamp < timestamp2 >> group by country. >> >> What's the right thing to do when faced with such a requirement? >> >> we could do a temp view like below? >> >> if (doc.timestamp > T1 & doc.timestamp < T2) emit(doc.location_path,doc) >> >> But aren't temp views considered bad for performance. >> >> Please do suggest the best way to solve this problem in couchdb. >> >> >> Rgds, >> Aroj >> >> >> On 14 Mar 2011 18:59, "Kinley Dorji" <[email protected]> wrote: >> >
