Linq2Couchbase in C# to filter outer documents based on their id non existence in inner documents

Linq2Couchbase in C# to filter outer documents based on their id non existence in inner documents.

I have two types of documents, message and hiddenMessage. hiddenMessage is a type that contains list of records identifying the messages that are hidden for a particular user. Now when listing documents from message type, I want to ignore (not list) those messages that are present/exists in the hiddenMessage.

How do I achieve this? Any help would be greatly appreciated.

Regards,
Aditya.

Hi @apasumarthi1999,

In the future, you might want to post .NET/C# related questions to the .NET forum here: https://www.couchbase.com/forums/c/net-sdk

That being said, I’m tagging @btburnett3, as he might be able to help you.

@apasumarthi1999

That question is somewhat difficult, as it’s a question of exclusion rather than inclusion. I would try something along these lines, though I’m not certain it will work. I’m also making some assumptions about your document/POCO structures, hopefully it makes sense. In particular, I’m assuming the document key of your hiddenMessages document includes the user’s so we can get it directly using UseKeys.

from p in context.Query<Message>()
where !context.Query<HiddenMessages>().UseKeys('hiddenMessages-' + userId.ToString())
    .SelectMany(q => q.HiddenMessageIds).Any(q => q == p.Id)

Thanks @btburnett3 I’ll try your suggestion and will get back on the results.