incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven.Prent...@nextgen.net
Subject Simulating SQL 'LIKE %' using Regular Expressions
Date Wed, 02 Jun 2010 01:01:21 GMT
Hi, so in my couchDB, what I want to happen is when you query a view in 
the design doc and providing ?key="C" at the end, bring up all shop names 
that start with C.
to do this I have made the following map function:

function(doc) 
{ 

  for (id in doc.Stores)
  {
 
  var strqry = doc.Stores[id]["name"].match(/^.*/);
 
    if (strqry)
    { 
      emit(strqry, doc.product_name + " qty: " + 
doc.Stores[id].item_count);
    }
  } 
}

When I run this from the temp view in Futon, I get a list of all stores 
and products (which made me think 'yay it worked, all it needs is a 
parameter') but when I use:
http://host:5984/db/design/name/_view/function?key="C" I get back: 
{"total_rows":30,"offset":0,"rows":[]}

my ultimate aim is to get it working similar to an SQL Like % so if for 
example I say ?key="C" it will return "Computer Store A" and so on..
I created my function based on this tutorial: 
http://books.couchdb.org/relax/reference/views-for-sql-jockeys



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message