'Node JS Using AND or OR operator - Fetching data

Good Day!

I need help on the below issue: Goal: is to filter data depending on the department content. What I'm trying to do is to fetch data from MongoDB based on your designation or department. For example, I'm from the Email Team:

I was able to fetch the data correctly using the below code:

return Announcement.find({ department: params.department }).collation({locale:'en',strength: 2}).sort({createdOn:1}).then(announcement => {
        return announcement
    })

However, what I'm trying to achieve is to get the data from the "All" department. For example, Email Team data plus the All data. This is a notification app. Wherein agents will receive or be notified if there are news recently published.

Example: As admin I have the option to assign a news to a specific department. I'm using a ComboBox for the selection: All, Email, Chat, Phone

So, if I selected All, since I'm from the email team, I should be getting the notification too.



Solution 1:[1]

After few minutes of research, I found this:

return Announcement.find({ $or: [{"department" : "All"},{department: params.department}]}).collation({locale:'en',strength: 2}).sort({createdOn:1}).then(announcement => {
        return announcement
    })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark Willow Aldave