Answer the question
In order to leave comments, you need to log in
How to include condition in mongoose search?
Good evening.
There is a problem. I have a request to a bot. Depending on the presence of the flag in this query, I must enable search restrictions or disable it.
Conventionally, I have a list of users that have a registrationDate, name and activated field.
I want to extract regardless of the registration date in case if there is no flag (boolean type flag) and if there is, then only after a certain date.
There is a method.
//DB.getUsers - алиас для функции find() со стандартными параметрами.
let result = await db.getUsers({
activated: true,
// Здесь
flag ? (registrationDate: {$gt: Date.now()}) : null
}, selectOptions)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question