I have a collection in Azure CosmosDB, and each document looks like this:
{
"id": "random",
"TeacherName": "Ben",
"Students": [
{
"Name": "John",
"Telephone": ""
},
{
"Name": "Mary",
"Telephone": ""
}
],
}
TeacherName is string, Students is a list of student
I need to do: Given a user name (user1), query and return all the documents, either teacher name is "user1" or there is a student with name "user1".
I tried a few options, but cannot do it.
The closest solution I found so far is to use .SelectMany()
, but I found .SelectMany
will do a join and will duplicate the return results.
This is my query:
client.CreateDocumentQuery().SelectMany((x) => x.Students.Where(s=>s.Name == "user1" || x.TeacherName == "user1")
If only the above sample document in the collection, and when I searched user name "Ben", 2 records will be returned ((number of result) * (number of students)). I have to remove the duplicate at client side and pagination is kind of broken.
Is it possible to issue a single query to achieve what I need?