You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Σπύρος Σβορώνος <sp...@hotmail.com> on 2014/06/16 12:11:50 UTC

Question in viewings

Hi everyone,
I am quite new and i have a relatively simple question for which i do not seem to find the answer. When i try to view a field that has a name which is a number (e.g. A field named "123"), if i write something like:

function(doc)
{
If (doc.123)
{ list of args}
}

I get an error saying that the expression does not eval to a function. Does anybody know how can i view a field that has this structure?

Thanks in advance,
Spiros

Re: Question in viewings

Posted by Mark Hahn <ma...@hahnca.com>.
Actually a number should work since it will be coerced into a string.  At
least this happens in Chrome.

I know using auto-coercion is uncool but I thought I'd just throw that out
there.


On Mon, Jun 16, 2014 at 12:40 PM, Jens Alfke <je...@couchbase.com> wrote:

>
> On Jun 16, 2014, at 3:29 AM, Pieter van der Eems <
> p.van.der.eems@interactiveblueprints.nl> wrote:
>
> > doc[123];
>
> That should be
>         doc["123"];
> since the key is a string, not a number.
>
> —Jens

Re: Question in viewings

Posted by Jens Alfke <je...@couchbase.com>.
On Jun 16, 2014, at 3:29 AM, Pieter van der Eems <p....@interactiveblueprints.nl> wrote:

> doc[123];

That should be
	doc["123"];
since the key is a string, not a number.

—Jens

Re: Question in viewings

Posted by Mike Marino <mm...@gmail.com>.
> Am 16.06.2014 um 12:29 schrieb Pieter van der Eems <p....@interactiveblueprints.nl>:
> The problem you encounter here has to do with javascript.
> Javascript does not allow you to do doc.123.
> It will allow you to access the "123" of doc by using the alternate syntax:

+1

I'll only add it is also a good idea to use a tool to check your
JavaScript syntax, eg jshint

http://www.jshint.com

They're also a number of online tools that would do the same.

Cheers,
Mike

Re: Question in viewings

Posted by Pieter van der Eems <p....@interactiveblueprints.nl>.
2014-06-16 12:11 GMT+02:00 Σπύρος Σβορώνος <sp...@hotmail.com>:
> Hi everyone,
> I am quite new and i have a relatively simple question for which i do not seem to find the answer. When i try to view a field that has a name which is a number (e.g. A field named "123"), if i write something like:
>
> function(doc)
> {
> If (doc.123)
> { list of args}
> }
>
> I get an error saying that the expression does not eval to a function. Does anybody know how can i view a field that has this structure?

The problem you encounter here has to do with javascript.
Javascript does not allow you to do doc.123.
It will allow you to access the "123" of doc by using the alternate syntax:
doc[123];


Try it with :
function (doc) {
  if (doc[123]) {
    // do stuff
  }
}

It might be a good idea to read more about javascript.
It's a strong but sometimes strange language :-)

With regards,
Pieter van der Eems
Interactive Blueprints

Re: Question in viewings

Posted by Σπύρος Σβορώνος <sp...@hotmail.com>.
Thanks for yous replies guys! I ll have a more in depth look into javascript!
Cheers