You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Norman Barker <no...@gmail.com> on 2010/09/20 23:14:20 UTC

Fwd: Multi-View support : feedback,issues, and question

somehow user and dev got cut off this, see below for an example..

Hi,

I have taken your example (and I have also uploaded the latest code to git).

Create the following documents

{
  "type": "B",
  "created_at": "20100920"
}

{
  "type": "A",
  "created_at": "20100920"
}

{
  "type": "B",
  "created_at": "20100919"
}

and then create two views that emit the type and created_at properties
as keys (as strings)

{
  "_id": "_design/main",
  "language": "javascript",
  "views": {
      "by_date": {
          "map": "function(doc) {
               if (doc.created_at)
                   emit(doc.created_at, null);
                }"
      },
      "by_type": {
          "map": "function(doc) {
                if (doc.type)
                  emit(doc.type, null);
               }"
      }
  }
}

using curl then post

curl -X POST http://localhost:5984/sample/_multi -d @sample.json

where sample.json contains

{
   "views":[
       "/sample/_design/main/_view/by_type?startkey=\"A\"&endkey=\"A\"",
       "/sample/_design/main/_view/by_date?startkey=\"20100920\"&endkey=\"20100920\""
   ]
}

to get all doc ids which are of type A on the 20th September.

There will be one id returned.

thanks,

Norman

On Mon, Sep 20, 2010 at 11:34 AM,  <cd...@free.fr> wrote:
> Hi,
>
> Sorry there is something I don't understand in your explanation.
>
> IMHO If I need to query on two distinct attributes (properties) of a document I'd need only two views, not three.
>
> If I have a docs like  :
>
>   {
>      "type" : "some value",
>      "created_at" : "some_date"
>   }
>
> If I'd like to get all the docs for a given time range, I'd create a view with created_at as key. Then I can pass a (startkey,endkey) pair of params to filter on the time range and get the appropriate documents.
>
> Now if I'd like all the documents of a given type, I'd create a view with type as key. Then I can pass a key param in order to get all the docs of a given (key) type.
>
> So, from my point of view I'd need only those two views to get all the docs of a given type and created in a given time range. Am I wrong ?
>
> If not, how should I pass the keys when invoking the multiview ? Could you please post an example, beacause I'm pretty sure it would clarify many things.
>
> Thanks again
>
> Regards,
>
> cdrx
>
>
>> Hi,
>>
>> thanks again for testing this.
>>
>> <snip>
>>
>>> However what I'd like to know if it is possible to pass parameters (keys, ranges)  to the "called views" map functions ( in this example views "test" in _design/three and _design/four ) ?
>>>
>>> Something like : return all documents which id is a multiple of N _and_ ,  for instance , is created in a given time range (assuming we have a creation date field in the doc).
>>>
>>> Is this case covered by the multiview feature ?
>>>
>>
>> yes,
>>
>> this would be three views in the body of the JSON document posted to the server.
>>
>> One view for each of the ranges where you are querying the ids for
>> mulltiples and the a view query with a startkey and endkey for the
>> date range.
>>
>> I use the multiview for this use case, documents between a two dates
>> with values X.
>>
>> Norman
>
>

Re: Fwd: Multi-View support : feedback,issues, and question

Posted by cdr53x <cd...@free.fr>.
Hi,

I checked out your update from the github and the mutiview test still 
produces the same 400 errors :

[Tue, 21 Sep 2010 09:00:29 GMT] [info] [<0.172.0>] 127.0.0.1 - - 'POST' 
/test_suite_db/_multi 400
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.172.0>] httpd 400 error 
response:
  {"error":"bad_request","reason":"Only reserved document ids may start 
with underscore."}

[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] 'POST' 
/test_suite_db/_multi {1,1}
Headers: [{'Accept',"application/json"},
           {'Accept-Charset',"ISO-8859-1,utf-8;q=0.7,*;q=0.7"},
           {'Accept-Encoding',"gzip,deflate"},
           {'Accept-Language',"en-us,en;q=0.5"},
           {'Cache-Control',"no-cache"},
           {'Connection',"keep-alive"},
           {'Content-Length',"52"},
           {'Content-Type',"application/json; charset=UTF-8"},
           {'Host',"127.0.0.1:5985"},
           {'Keep-Alive',"115"},
           {'Pragma',"no-cache"},
           
{'Referer',"http://127.0.0.1:5985/_utils/couch_tests.html?script/couch_tests.js"},
           {'User-Agent',"Mozilla/5.0 (X11; U; Linux x86_64; en-US; 
rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10"}]
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] OAuth Params: []
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] Minor error in HTTP 
request: {bad_request,
<<"Only reserved document ids may start with underscore.">>}
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] Stacktrace: 
[{couch_doc,validate_docid,1},
              {couch_httpd_db,db_doc_req,3},
              {couch_httpd_db,do_db_req,2},
              {couch_httpd,handle_request_int,5},
              {mochiweb_http,headers,5},
              {proc_lib,init_p_do_apply,3}]
[Tue, 21 Sep 2010 09:00:29 GMT] [info] [<0.174.0>] 127.0.0.1 - - 'POST' 
/test_suite_db/_multi 400
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] httpd 400 error 
response:
  {"error":"bad_request","reason":"Only reserved document ids may start 
with underscore."}
...

BTW there are no changes in the local.ini ( nor default.ini ) files 
concerning the _multi in section http_db_handlers on the github in the 
recent commit.

I added the section in local.ini with the content you provided in your 
mail and it did not change a thing. I also tried to add it in the 
default.ini, but had the same result.

For now all I can tell is that I am unable to test this feature with the 
source from github.

Regards,

Cdrx



Re: Fwd: Multi-View support : feedback,issues, and question

Posted by cdr53x <cd...@free.fr>.
Hi,

I checked out your update from the github and the mutiview test still 
produces the same 400 errors :

[Tue, 21 Sep 2010 09:00:29 GMT] [info] [<0.172.0>] 127.0.0.1 - - 'POST' 
/test_suite_db/_multi 400
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.172.0>] httpd 400 error 
response:
  {"error":"bad_request","reason":"Only reserved document ids may start 
with underscore."}

[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] 'POST' 
/test_suite_db/_multi {1,1}
Headers: [{'Accept',"application/json"},
           {'Accept-Charset',"ISO-8859-1,utf-8;q=0.7,*;q=0.7"},
           {'Accept-Encoding',"gzip,deflate"},
           {'Accept-Language',"en-us,en;q=0.5"},
           {'Cache-Control',"no-cache"},
           {'Connection',"keep-alive"},
           {'Content-Length',"52"},
           {'Content-Type',"application/json; charset=UTF-8"},
           {'Host',"127.0.0.1:5985"},
           {'Keep-Alive',"115"},
           {'Pragma',"no-cache"},
           
{'Referer',"http://127.0.0.1:5985/_utils/couch_tests.html?script/couch_tests.js"},
           {'User-Agent',"Mozilla/5.0 (X11; U; Linux x86_64; en-US; 
rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10"}]
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] OAuth Params: []
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] Minor error in HTTP 
request: {bad_request,
<<"Only reserved document ids may start with underscore.">>}
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] Stacktrace: 
[{couch_doc,validate_docid,1},
              {couch_httpd_db,db_doc_req,3},
              {couch_httpd_db,do_db_req,2},
              {couch_httpd,handle_request_int,5},
              {mochiweb_http,headers,5},
              {proc_lib,init_p_do_apply,3}]
[Tue, 21 Sep 2010 09:00:29 GMT] [info] [<0.174.0>] 127.0.0.1 - - 'POST' 
/test_suite_db/_multi 400
[Tue, 21 Sep 2010 09:00:29 GMT] [debug] [<0.174.0>] httpd 400 error 
response:
  {"error":"bad_request","reason":"Only reserved document ids may start 
with underscore."}
...

BTW there are no changes in the local.ini ( nor default.ini ) files 
concerning the _multi in section http_db_handlers on the github in the 
recent commit.

I added the section in local.ini with the content you provided in your 
mail and it did not change a thing. I also tried to add it in the 
default.ini, but had the same result.

For now all I can tell is that I am unable to test this feature with the 
source from github.

Regards,

Cdrx