incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bryan rasmussen <rasmussen.br...@gmail.com>
Subject Re: multiple keys query for a view with multiple key outputs
Date Mon, 11 Nov 2013 13:49:32 GMT
Well, yeah I can also do keys query with a GET instead of a POST, for
example the query

return_by_ip?keys=["18.72.0.3","18.72.0.5"]

on this view
function(doc) {
if(!doc.private){
  emit(doc.ip, {ip: doc.ip, value: doc.value, timestamp: doc.timestamp,
meta: doc.meta, membername: doc.membername});
}else{
  emit(doc.ip, {ip: doc.ip, value: doc.value, timestamp: doc.timestamp,
meta: {}, membername: ""});

}}
returns

{"total_rows":8,"offset":0,"rows":[
{"id":"3555d297d63d2d6cfdc29cc96b0003de","key":"18.72.0.3","value":{"ip":"18.72.0.3","value":"enum
{\n   NSWindowsNTOperatingSystem = 1,\n
NSWindows95OperatingSystem,\n   NSSolarisOperatingSystem,\n
NSHPUXOperatingSystem,\n
NSMACHOperatingSystem,","timestamp":"2013-07-30T08:43:34.290Z","membername":"pantagruel"}},
{"id":"3555d297d63d2d6cfdc29cc96b00105b","key":"18.72.0.3","value":{"ip":"18.72.0.3","value":"hash
= {:item1 => 1}\n\nafter that a want to add item2 so after this I have
hash like this:\n\n{:item1 => 1, :item2
=>2}","timestamp":"2013-07-30T08:58:10.490Z","membername":"pantagruel"}},
{"id":"3555d297d63d2d6cfdc29cc96b002a5c","key":"18.72.0.3","value":{"ip":"18.72.0.3","value":"request.body[key_val].toString();","timestamp":"2013-07-30T09:53:11.401Z","meta":{"computername":"sonias-macbook-pro.local"},"membername":"pantagruel"}},
{"id":"60d6802863b84074aa6a554b69000ec3","key":"18.72.0.3","value":{"ip":"18.72.0.3","value":"key_val","timestamp":"2013-08-01T08:05:57.250Z","meta":{"computername":"sonias-macbook-pro.local"},"membername":"pantagruel"}},
{"id":"91d0304f144ab4079d0af2c8b6000227","key":"18.72.0.3","value":{"ip":"18.72.0.3","value":"something
is up","timestamp":"2013-05-02T09:15:15.742Z","membername":"pantagruel"}},
{"id":"3555d297d63d2d6cfdc29cc96b001dc2","key":"18.72.0.5","value":{"ip":"18.72.0.5","value":"request.body[key_val].toString();","timestamp":"2013-07-30T09:52:56.687Z","meta":{},"membername":"pantagruel"}},
{"id":"9526ad9856812e376199c21a7c003250","key":"18.72.0.5","value":{"ip":"18.72.0.5","value":"Defined
by the Antarctic Treaty as everything south of latitude 60°S. AQ
domain names are available to government organizations who are
signatories to the Antarctic Treaty and to other registrants who have
a physical presence in Antarctica. \t  \tNo \tYes .ar \t Argentina. Ok
then. ","timestamp":"2013-01-02T09:15:15.742Z","meta":{},"membername":""}},
{"id":"e2fcb673a91c7c686e9436f41f003b12","key":"18.72.0.5","value":{"ip":"18.72.0.5","value":"http://www.junglegym.dk/faq/","timestamp":"2013-07-03T10:49:12.674Z","membername":"pantagruel"}}
]}

Which is what I want, in so far as I have all docs with the two ip number
keys I queried for, but the problem is I want to sort the results by the
timestamp value.

What would be the most efficient way to do that? Since the example data set
above will probably be a lot bigger in real world use it is not going to
work to query from the server and then sort afterwards.

Thanks,
Bryan


On Mon, Nov 11, 2013 at 11:13 AM, Dave Cottlehuber <dch@jsonified.com>wrote:

>
>
> On 11. November 2013 at 10:01:53, bryan rasmussen (
> rasmussen.bryan@gmail.com) wrote:
> >
> > Ok, well I can of course make a view that emits the ip and then do
> > keys=["18.72.0.3", " 617.253.1101"] etc. etc.
> > But I also want to be able to sort by the timestamp in various ways.
> > How should I do that?
> >
> >
> > Thanks
>
> Hi Bryan,
>
> Likely you will want to have a number of different views for these query
> types, as Jens suggests.
>
> CouchDB is optimised for range queries, but you can also send multiple
> keys in a single request using POST instead of GET
> https://couchdb.readthedocs.org/en/latest/api/ddoc/views.html?highlight=post%20query#post--db-_design-ddoc-_view-view
>
> There are some space efficiencies for using multiple views within the same
> design doc, but obviously you increase rebuild time & also the need to
> rebuild a view because of a change to a different view within the same ddoc.
>
> A+
> Dave
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message