2

If I have the following DB model in mongoose

Employee{
    FirstName : String,
    LastName : String,
    Job  : String,
}

and I have two docs that look like this:

{
   FirstName : Bob,
   LastName : Jackson
   Job : Professor
}

{
   FirstName : Michael,
   LastName : Jackson,
   Job : Professor,
}

if I have a query that does the following:

Employee.find{FirstName : "Michael" , LastName : NULL,  Job : NULL}

It will return null.

Instead I want to ignore the fields that have parameters equal to NULL as they do not exist in the query and the query above I wanted to be treated as :

Employee.find{“FirstName : Michael”} 

how can I do that?

1 Answer 1

1

I just need to do something like

Employee.Find(FirstName : new Regex(firstNameParam,i),
LastName : new Regex(lastNameParam,i),
Job  : new Regex(jobParam,i))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.