I'm trying to query my collection to display list of : reports & report section for some specific user level allowed to view. The collection looks like this :
{
"ReportName" : "Report A",
"ReportID" : "1",
"ReportSection" : [
{
"SectionName" : "ReportSection A",
"AllowedLevel" : [
"1",
"2"
]
},
{
"SectionName" : "ReportSection B",
"AllowedLevel" : [
"1",
"2",
"3"
]
},
{
"SectionName" : "ReportSection C",
"AllowedLevel" : [
]
}
]
}
The parameter of the query is user level. For example the user level "2" will be allowed to view Report & Section :
- Report A & Report Section A
- Report A & Report Section B
For now I have to Query like this :
db.Report.find({
"ReportSection.AllowedLevel":"2"
});
I get list of report and then in the application, I have to check every report section for allowed level. I believe there is a better solution for this.
I expect to have the result like this (assuming the user level : "2")
{
"ReportName" : "Report A",
"ReportID" : "1",
"SectionName" : "ReportSection A",
},
{
"ReportName" : "Report A",
"ReportID" : "1",
"SectionName" : "ReportSection B",
}