Do i need to escape keys when loading from a view?

i have a view emiting what looks like this

Key | Value
---------------------
one | something
two | something
a.b | something

now when querying, i can't get the a.b to show up, i'm assuming its the period in the middle. what do i have to do to get it to work? the other 2 show up fine.

ie:

$keys = ["one","two","a.b"];
$this->Couch()->view("dev_domain", "FullNameView",array("keys"=>array_keys($keys)));

only returns one and two.

Also not in love with having to use array_keys, but that's another issue.

Thanks

3 Answers

« Back to question.

I have the same problem searching for keys that contain special character.
I updated my .Net Client to 1.3.3 and make sure Im using the correct version of Newtonsoft.

{
"name": "Abercrombie & Fitch Company",
"isactive": true,
"sysdate": "2014-02-09T19:32:48",
"type": "company"
}
{
"name": "Jason's Store",
"isactive": true,
"sysdate": "2014-02-09T19:32:48",
"type": "company"
}
{
"name": "A.H. Belo Corporation",
"isactive": true,
"sysdate": "2014-02-09T19:32:48",
"type": "company"
}

function (doc, meta) {
if (doc.type == "company" && doc.name) {
emit(doc.name, null);
}
}

protected IView GetView(string name, string startKey, string endKey, int limit, bool isProjection = false)
{
string test = "Abercrombie & Fitch Company";
return _Client.GetView(_designDoc, name, isProjection).StartKey(test).EndKey(endKey).Limit(limit);
}

Error:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type....
because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.
Newtonsoft.Json.JsonException {Newtonsoft.Json.JsonSerializationException}

« Back to question.

Hello,

Doing the following works for me:

$keys = array("one","a.b");
$results = $cb->view("test", "by_id",  array('keys' => $keys) );

Note: I am not a PHP specialist just doing basic tests. Is it ok for your application?

Regards
Tug
@tgrall

« Back to question.

Its better to fix your output by making a better map function. Remember the mapper is javascript so you can use basic function to check and/or cleanup what you emit.

if you put up some of your data and your current map function I might be able to help you.

Appreciated,

but this is the data i want, so hopefully the answer isn't the standard 'don't do that'..

if my data is a.b ie: that is the value of the property i want to search on, how would you handle it? there could be any number of special characters, . is just the first time it broke.

Bill.

you cann't do regualar expressions with the view perimeters when calling the view. You can control it on the application level by looping through the view results

OR

You would xdcr your data to Elastic Search. It have powerful tools.
http://www.couchbase.com/docs/couchbase-elasticsearch/couchbase-elastic-...

Hi,

I'm not trying to do regular expressions at all, simply trying to query a view by its key... and it's key happens to contain a "."

seems like elastic search is a heavy solution to 'how do i query for a key containing a period'