This is about displaying documents of a collection based on the logged in user's role/team. Please help me correct the part of the query which uses $in operator.
The user model includes below fields apart from others:
userName: { type: String, unique: true, required: true },
manager: String,
isManager: Boolean,
managesAll: Boolean,
team: [{
userId: String,
userName: String,
isManager: Boolean
}],
There is a collection 'servicelog'. One of the fields of the servicelog document is "execName". When the list of servicelog is displayed, depending on the logged in user the log shd be displayed in one of the three ways:
if(user.role === 'Admin' || user.managesAll === true) {
// display all documents
docQuery = ServiceLog.find().collation({ locale: 'en'});
} else if(user.isManager === true) {
// display where execName is userName or one of the userName in user.team
docQuery = ServiceLog.find({
$or: [
{ execName: user.username },
{ execName: { $in: user.team } }, // PLS HELP CORRECT THIS PART. How do I look in user.team.userName
],
});
} else if(user.isManager === false) {
// display where execName is userName
docQuery = ServiceLog.find({ execName: user.username });
}