Views using .Key(.....) returns no results

Hi I want to use a complex object as a key in my view

my documents are stored as json.


“projectId”: {
“id”: “85e0d814-071e-4c7d-9369-5b46fc3935aa”
},

I want to find documents by ProjectId which is a class with an Id property. I want to encapsulate my ids as value objects. But I might end up using simple strings if i cannot make this work.

the view is defined like this:

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

querying the view from management web site gives:

{“total_rows”:12,“rows”:[
{“id”:“9a56e3dc-f5c1-41bc-8f23-c60d5d84bc07”,“key”:{“id”:“237e2d3d-cfcc-415d-b8cb-87b2cf94bb1c”},“value”:null},
{“id”:“e758d4e0-31e8-477c-8f5e-64038f23bd30”,“key”:{“id”:“238166f6-9a67-48cc-9f78-241ebc22b700”},“value”:null},
{“id”:“c65b4c2e-c848-419e-93b1-852dd165fdfb”,“key”:{“id”:“283068d5-fd2a-4cb7-bf02-4e1e5efaab03”},“value”:null},
{“id”:“a34205bf-72e7-4bd1-a73a-180dbfaf5ea1”,“key”:{“id”:“58d50df5-98c0-4e32-8c7b-fd85e8101e57”},“value”:null},
{“id”:“3ecd7415-4034-4f84-87bf-3838085f1cef”,“key”:{“id”:“782fa0f6-2f46-4664-9c8c-9ede20d3affe”},“value”:null},
{“id”:“697243ac-90ba-46c9-a995-365181573458”,“key”:{“id”:“782fa0f6-2f46-4664-9c8c-9ede20d3affe”},“value”:null},
{“id”:“b487a8da-c97a-4c86-92d9-e2d74f55d5ab”,“key”:{“id”:“782fa0f6-2f46-4664-9c8c-9ede20d3affe”},“value”:null},
{“id”:“187a2527-bd96-4560-8492-51fefdae6692”,“key”:{“id”:“85e0d814-071e-4c7d-9369-5b46fc3935aa”},“value”:null},
{“id”:“200ab3e1-de34-4482-92b4-3b4073547ecb”,“key”:{“id”:“8de2d56a-da3f-406a-8508-40f3ffb5430e”},“value”:null},
{“id”:“868118c5-83c9-4dd8-a06d-50924e1995e2”,“key”:{“id”:“aacb7ae9-a16e-42a6-bac1-f132a840929b”},“value”:null}
]
}

using the following code in .net sdk works fine

var view = Client.GetView(_designDoc, “by_project”, true);

it gives me all 12 rows.

How ever i’m only interested in those that match a particular projectId.

So I added the .Key method

var view = Client.GetView(_designDoc, “by_project”, true).Key(projectId);

this gives no result. also tried using

var view = Client.GetView(_designDoc, “by_project”, true).Key(projectIdAsJson);

or

var view = Client.GetView(_designDoc, “by_project”, true).Key(projectIdAsJson);

I also tried using the generic version of GetView.
Nothing helps.

Any Ideas?

ultimately i would like to use

var result = Client.GetView(_designDoc, “by_project”, true).Key(projectId);

Another question how would one use
the generic Version of Key with a multivalue key? like object[]{type1, type2} ?

Thanks

Hi ccjohansen -

If projectId is a primary key you could just do a regular Get(projectId)? This doesn’t actually answer your question of why Key(…) isn’t working…i’ll have to run through the code.

-Jeff

Hi
No its not the primary key.