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


#1

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.


#2

Hi @apasumarthi1999,

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

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


#3

@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)

#4

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