find documents on the basis of array of object id in mongoose

134
January 17, 2022, at 03:20 AM

I have a user model with two roles

  1. Manager
  2. Employee

Each manager has an manager idea that references the User model

I have a new model called Customers The customers will either have user id of manager or employee

I want to create a controller to view the customers that are under the manager and the employees of that manager

let employees= await Employee.find({ managerId: req.user._id });
const customers= await Customer.find({
      registeredBy: { $in: [employees._id] },
    });

this is only returning the customers that are NOT registered by any employee or manager. What is the correct way to achieve this?

edit This is how my customer collection looks like

_id:ObjectId('61e2a99752f9023ef0f9a1a6')
serialNo:"421A"
registeredBy:ObjectId('61d02ae060ccdd5a7a95813a')

If the manager is searching, the record of all the Customers having that manager id as registeredBy as well as the Customers having registerBy of the employees that have that *managerId in Employee schema should be shown

Rent Charter Buses Company
READ ALSO
Error connecting SQLAlchemy to MYSQL db - Error: While importing 'app', an ImportError was raised

Error connecting SQLAlchemy to MYSQL db - Error: While importing 'app', an ImportError was raised

I'm trying to connect a MySql database to my flask app and I'm getting an import error of appI have tried various ways and have settled with the create_engine route

111
Android Compose Bottom Navigation

Android Compose Bottom Navigation

I have a problem with compose bottom navigation barWith starting screen to be exact

137
Align the non-paranted objects using js (responsive webite)

Align the non-paranted objects using js (responsive webite)

Here's an example of what I am trying to achieve:

132
How to animate any click event [duplicate]

How to animate any click event [duplicate]

I have written this code to remove an element now I want give any effect to it using jQuery

87