On 2008-09-25 10:17:16 -0400, Adam Kocoloski
<[EMAIL PROTECTED]> said:
You should be able to get the latest revision without a reduce
(generally a good thing to avoid if you can). Something like
function(doc) {
if( doc.class == "RemoteUrl" && doc.content ) {
emit([doc.normalized_url, doc.created_at], doc);
}
}
will give you all your documents sorted first by URL and then by
revision time. Then you can query the view with some combination of
startkey, count, and maybe descending=true (depending on how your
revision dates sort) to get the latest revision of a particular doc.
Alternatively, if you wanted to suppress all old revisions in the view
you could add a simpler reduce function which takes advantage of the
map sorting the results for you:
function(keys, values) {
return values[0]; // or maybe values.pop();
}
thats interesting... I didn't realize that what got passed back to the
reduce function was sorted. My instinct is to make queries return what
i want and not put logic in the app, if only to limit the amount of
data moved over the wire.
If you don't need to analyze the bulk-data in any view you could
consider storing it as an attachment to a doc. Details are at the
bottom of this page:
http://wiki.apache.org/couchdb/HttpDocumentApi
I missed this whole thing of an attachment! I'll be doing the analysis
on the ruby side, so I just need the DB to manage the data, not
transform it at all.
Yeah, I guess that's a bit tricky. If the data volume doesn't get in
your way you could emit [places.lat, places.long] as the key, query
the view with your latitude range as startkey and endkey, and then
pick out documents in your longitude range client-side. Others may
well have more clever suggestions. Best,
Ug.
Thanks for the prompt reply.
-w