couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tito Ciuro <>
Subject Re: Matching docs which values ending with a specific string
Date Wed, 12 Feb 2014 23:10:31 GMT

Ah! I see. Well, what if I stored the path in an array instead?:

  "_id" : "12345",
  "location" : [<some_city>,<some town>]

If I emit (doc.location,doc._id), would I be able to write a query that matches the second
element of the doc.location array?

Thanks again for all the help,

-- Tito

On Feb 12, 2014, at 2:48 PM, Jason Winshell <> wrote:

> AFAIK, you're describing a CouchDB limitation. You may need to use CouchDB-Lucene to
get your answers. CouchDB views match keys in an index. You can match a prefix, but not a
tail. And you can't deal with case sensitivity. You might be able to generate a view in which
you reverse the chars of your location and then match in reverse order (i.e. turning the problem
into a prefix). I think trying to coerce Couch to do that is nutty. Just use CouchDB-Lucene.
> On Feb 12, 2014, at 2:35 PM, Tito Ciuro <> wrote:
>> Hello,
>> I have a database with documents with the following format:
>> {
>>   "_id" : "12345",
>>   "location" : <some_city>.<some town>
>> }
>> I have values like:
>> California.San Francisco
>> California.Los Angeles
>> Florida.Miami
>> ...
>> ...
>> What I'm trying to do is to match documents that "end with" a particular string.
Say I want to match all states where the town 'Anytown' exists:
>> California.Anytown
>> Florida.Anytown
>> Texas.Anytown
>> If I use the following query:
>> curl
>> It works and returns one document (as expected), but I cannot seem to make it work
when I look for an "end with" string. I have seen examples where %007F is used to match "begins
with". When I use it, I get a {"error":"bad_request","reason":"invalid_json"} message. So
I'm not sure how to proceed.
>> Any ideas? Thanks!
>> -- Tito

View raw message