Hello again,

I'm confused about one behavior I see with curl. If I enter the following URL:

http://127.0.0.1:5984/test/_design/test/_view/test-byTown?startkey=%5B%22foo%20ca%22%5D&endkey=%5B%22foo%20ca%22,%7B%7D%5D

the browser I get the following:

{"total_rows":2,"offset":0,"rows":[
{"id":"9b857ca67a2611d51595aa3ad0306f30","key":["foo 
ca","9b857ca67a2611d51595aa3ad0306f30"],"value":null}
]}

This works as expected. However, if I issue the same command with curl I get 
more than I expected:

curl 
http://127.0.0.1:5984/test/_design/test/_view/test-byTown?startkey=%5B%22foo%20ca%22%5D&endkey=%5B%22foo%20ca%22,%7B%7D%5D

TurboMonkey:_design tito$ {"total_rows":2,"offset":0,"rows":[
{"id":"9b857ca67a2611d51595aa3ad0306f30","key":["foo 
ca","9b857ca67a2611d51595aa3ad0306f30"],"value":null},
{"id":"9b857ca67a2611d51595aa3ad030733c","key":["foo 
fl","9b857ca67a2611d51595aa3ad030733c"],"value":null}
]}

Why do I get different outputs? (and why is curl not doing the right thing?)

Thanks again,

-- Tito

On Feb 12, 2014, at 8:38 PM, Tito Ciuro <[email protected]> wrote:

> Hi Kevin,
> 
> Yes, you're right. I'm still getting my head around Map/Reduce and I'm 
> learning how to better lay out the data constantly.
> 
> Thanks for the pointers. Much appreciated!
> 
> -- Tito
> 
> On Feb 12, 2014, at 6:26 PM, Kevin Coombes <[email protected]> wrote:
> 
>> Maybe you should completely describe the structure you want.
>> 
>> {
>> "_id": "12345",
>> "location": {
>>      "state": "California",
>>       "city": "Florence"
>> }
>> }
>> 
>> Because (1) you can define multiple views that emit any reasonable 
>> combination of city and state in any order you might want to query and (2) 
>> some day you might want to add an entry like
>> 
>> {
>> "_id": "98765",
>> "location": {
>>      "country": "Italy",
>>      "province": "Tuscany",
>>       "city": "Florence"
>> }
>> }
>> 
>> On 2/12/2014 6:10 PM, Tito Ciuro wrote:
>>> Hello,
>>> 
>>> 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 <[email protected]> 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 <[email protected]> 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 
>>>>> http://127.0.0.1:5984/example/_design/test/_view/ends-with-city?key=%22California.Anytown%22
>>>>> 
>>>>> 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
>> 
> 

Reply via email to