Comments on: CouchDB and logs… https://blog.maxaller.name/2008/08/couchdb-and-logs/ ruby, ubuntu, etc Thu, 17 Mar 2016 20:35:40 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Max https://blog.maxaller.name/2008/08/couchdb-and-logs/comment-page-1/#comment-22 Max Mon, 25 Aug 2008 19:38:19 +0000 http://giftswappo.com/wordpress/?p=35#comment-22 Sweet, I’m glad to learn I’m wrong if it means that things are better than I thought!

I’m a fan of IRC, so I think I’ll jump on there…

]]>
By: Jan https://blog.maxaller.name/2008/08/couchdb-and-logs/comment-page-1/#comment-21 Jan Mon, 25 Aug 2008 09:22:52 +0000 http://giftswappo.com/wordpress/?p=35#comment-21 Heya,

you got it all wrong :) Let’s see:

“But still, you have to create a view for every single user if you want to be able to select all the blog posts by any particular user — I’d imagine that could take up a lot of space, and CPU cycles. Alternatively, you could have a view that just returned all blog posts, and then filter through those in your application. Neither would be that good though, I feel, but I might be missing something.”

You’re close on this one: Create a view that returns all blogs, with the user as a key:

map: function(doc) { emit(doc.blog_user_id, null); }

A view with this function can be queried with key=$username parameter which gives you the your filtering. This is the preferred way of doing it and this use-case is lightning fast.

The session id problem is the same:

map: function(doc) { emit(doc.session_id, null); }

You can also do range queries with startkey=$start&endkey=$end in case of sequential keys (say a date).

Notice `null` as the second parameter of the emit() function. This means the view will stay lean and mean, but it also means that you need to fetch the actual document data with another request. If you can afford your view indexes to be big, you can put in the `doc`, instead of `null`. This is simply a trade-off.

In the `null` case where you’d need to fetch the doc data subsequently, you might wonder “what if I have a range with 10k docs”. Yes fetching them individually would be a pain. There is a patch in review at the moment, that will let you fetch all the associated doc data with a view result without actually storing it in the view. Watch out for that. For N < 100(0) docs, individual fetches are okay though.

Yes, documentation of all that could be improved, but there are only so many days in an an hour and hey, this is open source (lame excuse of the day :) .

Feel free to contact me about further questions but you’re best off subscribing to the CouchDB mailing lists (http://incubator.apache.org/couchdb/community/lists.html) or by hopping onto #couchdb on irc.freenode.org.

Cheers
Jan

]]>