couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Norman Barker <norman.bar...@gmail.com>
Subject Fwd: Multi-View support : feedback,issues, and question
Date Mon, 20 Sep 2010 21:14:20 GMT
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,  <cdr53x@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
>
>

Mime
View raw message