I thought this was a problem with couchrest, but seems to be a deeper internal Ruby problem. With the following couchdb view key/values:

...
{"key":["Document-2458","MethodID","286"],"value":1},
{"key":["Document-2458","MethodID","287"],"value":1},
{"key":["Document-2458","MethodID","288"],"value":1},
{"key":["Document-2458","MethodID","92"],"value":1},
...

If I ask for the view this way:

conn_str = 'http://127.0.0.1:5984/portal_development/_design/all_data_values/_view/view1?group=true'
key = '["Document-2458","MethodID","287"]'
result = JSON.parse(open(conn_str + "&key=" + CGI.escape(key)).read)
puts result

I get this result:

{"rows"=>[{"key"=>["Document-2458", "MethodID", "287"], "value"=>1}]}

But if I do this:

conn_str2 = 'http://127.0.0.1:5984/portal_development/_design/all_data_values/_view/view1?group=true'
key = '["Document-' + "2485" + '","MethodID","287"]'
result = JSON.parse(open(conn_str2 + "&key=" + CGI.escape(key)).read)
puts result

I get an empty result:

{"rows"=>[]}

I cannot for the life of me figure out why... I've even resorted to cracking open wireshark and watch both queries on the wire. The bytes in the data portion of the packet are identical (the stuff with the url and params). And I verify that couchdb is indeed sending me back non-empty data for the first, and empty data on the second. Couchdb even shows identical queries in the log:

[info] [<0.19053.0>] 127.0.0.1 - - 'GET' /portal_development/_design/all_data_values/_view/view1?group=true&key=%5B%22Document-2458%22%2C%22MethodID%22%2C%22287%22%5D 200
[info] [<0.19055.0>] 127.0.0.1 - - 'GET' /portal_development/_design/all_data_values/_view/view1?group=true&key=%5B%22Document-2485%22%2C%22MethodID%22%2C%22287%22%5D 200

The problem is whenever I concat the string instead of hard coding it, even thought the resulting string are the same. But I have no idea why. Thoughts?

有帮助吗?

解决方案

With the first key test you have Document-2458 where with the second one you have "Document-" + "2485".

As in, you have transposed the 8 and 5 on the end of the document id.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top