D
D
Daulet Nurzhanov2018-07-09 14:28:09
MongoDB
Daulet Nurzhanov, 2018-07-09 14:28:09

How to search for a document via ref to another model?

I have a User model that has an email field that is important for my task. I
also have an Employee model that has a user field: { ref: "User" }
the question is: how can I find an employee by email?
I did it through employee.find({}).populate() and from this result I go through each one and look for email. The
problem with this approach is that if there are a very large number of records in the database, then these operations will take a lot of time

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question