couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Noel Quintos <npquin...@gmail.com>
Subject Re: Return web request via GET with a specific format
Date Thu, 04 May 2017 22:50:39 GMT
I managed to save a list function as shown below in the last row:

$ curl http://172.16.54.8:5984/lightning/_all_docs\?include_docs\=true

{"total_rows":4,"offset":0,"rows":[
{"id":"94fdb18c0294e666f94cea2f53014830","key":"94fdb18c0294e666f94cea2f53014830","value":{"rev":"8-06e54ccb86e59676d5926caebdab7b33"},"doc":{"_id":"94fdb18c0294e666f94cea2f53014830","_rev":"8-06e54ccb86e59676d5926caebdab7b33","still_active":true,"multiplicity":1,"longitude":110.179,"elapsed_time":0,"intensity":0.0,"strike_type":"cloud
to cloud","latitude":58.914,"time_stamp":"2017-05-04T16:23:48.228000Z"}},
{"id":"94fdb18c0294e666f94cea2f5301573f","key":"94fdb18c0294e666f94cea2f5301573f","value":{"rev":"8-e8c840686355d470479a7bc03d8b56e2"},"doc":{"_id":"94fdb18c0294e666f94cea2f5301573f","_rev":"8-e8c840686355d470479a7bc03d8b56e2","still_active":true,"multiplicity":8,"longitude":118.763,"elapsed_time":0,"intensity":0.0,"strike_type":"cloud
to cloud","latitude":58.836,"time_stamp":"2017-05-04T16:23:48.228000Z"}},
{"id":"94fdb18c0294e666f94cea2f53015cfe","key":"94fdb18c0294e666f94cea2f53015cfe","value":{"rev":"8-f4c81acec498a8e2059170de0c477ff9"},"doc":{"_id":"94fdb18c0294e666f94cea2f53015cfe","_rev":"8-f4c81acec498a8e2059170de0c477ff9","still_active":true,"multiplicity":1,"longitude":113.242,"elapsed_time":0,"intensity":0.0,"strike_type":"cloud
to cloud","latitude":52.438,"time_stamp":"2017-05-04T16:23:48.230000Z"}},
{"id":"_design/doc","key":"_design/doc","value":{"rev":"14-4689f641dbc934b9bbc6f0ca8eb4dc2e"},"doc":{"_id":"_design/doc","_rev":"14-4689f641dbc934b9bbc6f0ca8eb4dc2e","id":"_design/doc","views":{"nv":{"map":"function(doc)
{\n emit(null, doc);\n}"}},"lists":{"lightning":"function(head, req) { var
row = getRow(); var firsttime = 1; if (!row) { send('[]'); } send('[\n');
while (row=getRow()) { if (firsttime) { send('\t{\n'); } else {
send('\t,{\n'); firsttime = 0; } send('\t\tattributes:'+row.value);
send('\t}\n'); } send(']\n'); }"}}}
]}

I have a view called "nv" with returned values below:
$ curl http://172.16.54.8:5984/lightning/_design/doc/_view/nv

{"total_rows":3,"offset":0,"rows":[
{"id":"94fdb18c0294e666f94cea2f53014830","key":null,"value":{"_id":"94fdb18c0294e666f94cea2f53014830","_rev":"17-94f163875b0573e3ac3feec283ef78a3","still_active":true,"multiplicity":1,"longitude":110.179,"elapsed_time":1,"intensity":0,"strike_type":"cloud
to cloud","latitude":58.914,"time_stamp":"2017-05-04T16:23:48.228000Z"}},
{"id":"94fdb18c0294e666f94cea2f5301573f","key":null,"value":{"_id":"94fdb18c0294e666f94cea2f5301573f","_rev":"17-81edddee8a3bab95b9b64f0b03c33a47","still_active":true,"multiplicity":8,"longitude":118.763,"elapsed_time":1,"intensity":0,"strike_type":"cloud
to cloud","latitude":58.836,"time_stamp":"2017-05-04T16:23:48.228000Z"}},
{"id":"94fdb18c0294e666f94cea2f53015cfe","key":null,"value":{"_id":"94fdb18c0294e666f94cea2f53015cfe","_rev":"17-ac5a7ead3eedc2e226133064dbd3fda3","still_active":true,"multiplicity":1,"longitude":113.242,"elapsed_time":1,"intensity":0,"strike_type":"cloud
to cloud","latitude":52.438,"time_stamp":"2017-05-04T16:23:48.230000Z"}}
]}

However, if I try viewing that list (apply lists function "lightning" to
view "nv"), I get this error message
$ curl http://172.16.54.8:5984/lightning/_design/doc/_list/lightning/nv

{"error":"compilation_error","reason":"Expression does not eval to a
function. (function(head, req) { var row = getRow(); var firsttime = 1; if
(!row) { send('[]'); } send('[\n'); while (row=getRow()) { if (firsttime) {
send('\t{\n'); } else { send('\t,{\n'); firsttime = 0; }
send('\t\tattributes:'+row.value); send('\t}\n'); } send(']\n'); })"}

I have no javascript background but nevertheless, I believe that is a valid
javascript function and the error might have to do with the JSON data
structure that I made for the lists. Does lists need to have functions
mapped to "map" just like views? I tried doing that the first time but I am
getting error saying:
{"error":"invalid_design_doc","reason":"`lists.lightning` field must have
string type"}

Thanks!

On Wed, May 3, 2017 at 9:34 AM, Aurélien Bénel <aurelien.benel@utt.fr>
wrote:

> > Formatting a view is done with a *`list`* function.
> > http://docs.couchdb.org/en/latest/couchapp/ddocs.html#list-functions
> >> Yes, it looks like "list" is what I am looking for. I am very new with
> CouchDB and just using Fauxton. I don’t see there any method of creating
> list under Design Document (it does allow me to create views, however). How
> do you create this manually, via Fauxton, if possible? Thanks!
>
> You could create them by editing the design document JSON directly, but it
> would a pain.
> Instead I recommend using command line commands to convert a tree of files
> and folders into a design document.
>
> There are several of them. Here is one I use:
>
>     https://github.com/couchapp/couchapp
>
>
> Regards,
>
> Aurélien




-- 
Noel P. Quintos

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