You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by "Luis M. Gonzalez" <lu...@gmail.com> on 2011/06/26 03:14:42 UTC

How to get the value of a reduce function?

I'm sorry if this is a stupid question,  I'm new to couchdb and although I
tried, I couldn't find the way to do this simple task.
I have created aview which computes the sum of all ages of a family members
(this is just for learning purpose, not very useful at all):

The view's url is this:
http://neuruss.iriscouch.com/_utils/database.html?family/_design/ages/_view/ages
The json result of this view is this one (as seen in "raw view"):

    {"rows":[
    {"key":null,"value":558}
    ]}

So, for displaying the value on my attachment (index.html), I use this
jquery snippet:

   $.getJSON("http://neuruss.iriscouch.com/family/_design/ages/_view/ages",
function(json){
   				$(".description").text(json.rows[0].value);

    });


But it doesn't work...

I suppose the result is a json object, so why can't I see the result?

I tried parsing it with "JSON.parse.." but it didn't work. I also
tried showing the whole json result, not just its value, but didn't
work either.

Any hint?


Thanks in advance...

Luis

Re: How to get the value of a reduce function?

Posted by Luis González <lu...@gmail.com>.
Jason Smith <jh...@...> writes:
> Another clue is that you are using a full, absolute URL in your
> example. That is okay, but perhaps you did that because your web page
> is from a different site?
> 

Hi everybody, thanks for your replies and sorry for my delay.
(I use to check this mailing list through Google Groups, and this is were I 
removed my question because I quickly realized I made a dumb mistake...).

I was using two different instances of my app while playing with it, and I tried 
accessing one from the other by mistake. So Jason, you are right...

Thanks again!
Luis



Re: How to get the value of a reduce function?

Posted by Jason Smith <jh...@iriscouch.com>.
On Thu, Jun 30, 2011 at 3:28 PM, Randall Leeds <ra...@gmail.com> wrote:
> On Sat, Jun 25, 2011 at 18:14, Luis M. Gonzalez <lu...@gmail.com> wrote:
>> I'm sorry if this is a stupid question,  I'm new to couchdb and although I
>> tried, I couldn't find the way to do this simple task.
>> I have created aview which computes the sum of all ages of a family members
>> (this is just for learning purpose, not very useful at all):
>>
>> The view's url is this:
>> http://neuruss.iriscouch.com/_utils/database.html?family/_design/ages/_view/ages
>> The json result of this view is this one (as seen in "raw view"):
>>
>>    {"rows":[
>>    {"key":null,"value":558}
>>    ]}
>>
>> So, for displaying the value on my attachment (index.html), I use this
>> jquery snippet:
>>
>>   $.getJSON("http://neuruss.iriscouch.com/family/_design/ages/_view/ages",
>> function(json){
>>                                $(".description").text(json.rows[0].value);
>>
>>    });
>>
>>
>> But it doesn't work...
>>
>> I suppose the result is a json object, so why can't I see the result?
>>
>> I tried parsing it with "JSON.parse.." but it didn't work. I also
>> tried showing the whole json result, not just its value, but didn't
>> work either.
>>
>
> You tried to show the whole result and it didn't work?
> Can you check what the value of "json" is? Maybe show something if
> it's == false or === undefined or null or something?

The example URL he gave does return a view result. But you might be right.

Luis, I do not see an index.html file attached in that design
document. One point of friction with CouchDB is the web browser
same-origin restrictions. For example, if you load index.html from a
foreign site and try to getJSON from your couch, you will not get the
query result.

Another clue is that you are using a full, absolute URL in your
example. That is okay, but perhaps you did that because your web page
is from a different site?

-- 
Iris Couch

Re: How to get the value of a reduce function?

Posted by Randall Leeds <ra...@gmail.com>.
On Sat, Jun 25, 2011 at 18:14, Luis M. Gonzalez <lu...@gmail.com> wrote:
> I'm sorry if this is a stupid question,  I'm new to couchdb and although I
> tried, I couldn't find the way to do this simple task.
> I have created aview which computes the sum of all ages of a family members
> (this is just for learning purpose, not very useful at all):
>
> The view's url is this:
> http://neuruss.iriscouch.com/_utils/database.html?family/_design/ages/_view/ages
> The json result of this view is this one (as seen in "raw view"):
>
>    {"rows":[
>    {"key":null,"value":558}
>    ]}
>
> So, for displaying the value on my attachment (index.html), I use this
> jquery snippet:
>
>   $.getJSON("http://neuruss.iriscouch.com/family/_design/ages/_view/ages",
> function(json){
>                                $(".description").text(json.rows[0].value);
>
>    });
>
>
> But it doesn't work...
>
> I suppose the result is a json object, so why can't I see the result?
>
> I tried parsing it with "JSON.parse.." but it didn't work. I also
> tried showing the whole json result, not just its value, but didn't
> work either.
>

You tried to show the whole result and it didn't work?
Can you check what the value of "json" is? Maybe show something if
it's == false or === undefined or null or something?