couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heiko Henning <greenrove...@gmail.com>
Subject map reduca with object as key
Date Wed, 17 Aug 2011 07:09:58 GMT
Hy,

i have create some demo pages like this:

{
     "_id": "rating_1",
     "type": "rating",
     "value": 90,
     "user": "max@educa.ch",
     "lom_id": "1337"
}

And a design document like:

{
     "_id": "_design/rating",
     "views":
     {
         "get_rating":
         {
             "map": "
                 function(doc){
                     if (doc.type == 'rating') {
                         emit({user:doc.user, lom_id:doc.lom_id}, 
doc.value);
                         emit({user:'all',    lom_id:doc.lom_id}, 
doc.value);
                     }
                 } ",

             "reduce": "
                 function(key, values, rereduce){
                     var result = new Object();
                     if(!rereduce)
                     {
                         return sum(values)/values.length;

                     }

                     return sum(values);
                 } "

         }
     }
}

When i view this with _utils, i will get:
http://picupload.org/i/2bd364369222.jpg

But a query like:
key = {"lom_id":"1337","user":"all"}
http://ubuntu:5984/testdb/_design/rating/_view/get_rating?group=true&key={%22lom_id%22%3A%221337%22%2C%22user%22%3A%22all%22}

retrun only a
rows:[]


Question:
Is there a possibility to have key as Object?

Or have i to do thinks like:

emit(doc.lom_id+'___'+user:doc.user, doc.value);
emit(doc.lom_id+'___all', doc.value);

Frindly Regards
Heiko



Mime
View raw message