couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastian Cohnen <sebastiancoh...@googlemail.com>
Subject Re: Map function with regular expression
Date Tue, 01 Jun 2010 09:04:58 GMT
Hey Steven,

I have not tested your code, but what seems to be the problem? are you getting errors or simply
not the output you anticipated?

Some hints though:
- you can use log() to emit messages to couchdb's logfile
- you should always use guards (like if (doc.Stores) { ... }) otherwise you can easily get
nasty bugs
- you can use the js console command to test your code

On 01.06.2010, at 09:09, Steven.Prentice@nextgen.net wrote:

> Hi,
> 
> Ive got a document containing an array and want to perform a regex on an 
> array item called name, it is located in the Stores field
> 
> what ive got at the moment is...
> 
> function(doc) 
> { 
> 
>  for (id in doc.Stores)
>  {
>    //regular expression to ensure a store name starts with "C" and ends 
> with "k"
>    var strqry = doc.Stores[id].name.match(/^C([a-z]*)k/);
> 
>    if (strqry)
>    { 
>      emit(doc.Stores[id].name, doc.product_name + " qty: " + 
> doc.Stores[id].item_count);
>    }
>  } 
> }
> 
> a javascript regex validator told me that that regex is correct, I think 
> it may be something wrong with the way that I am pointing the regex to the 
> "stores[id].name"
> 
> Cheers :)


Mime
View raw message