Node.js 使用mongoose find()设置要从模型中查找的自定义条件

Node.js 使用mongoose find()设置要从模型中查找的自定义条件,node.js,mongoose,mongoose-schema,Node.js,Mongoose,Mongoose Schema,我只想在Mongoosefind()中设置一些条件,以便从我的例程模型中进行查询。有可能吗?或者如何设置这样的自定义条件 const List = await Routine.find({ $where: () => { moment(currentDate).isBetween(this.startDate, this.endDate, undefined, '[]') == true &&

我只想在Mongoosefind()中设置一些条件,以便从我的例程模型中进行查询。有可能吗?或者如何设置这样的自定义条件

const List = await Routine.find({
        $where:
            () => {
                moment(currentDate).isBetween(this.startDate, this.endDate, undefined, '[]') == true &&
                    customFunc(this) == true
            }
    })

customFunc()从理论上返回一个布尔值时,您可以这样做。但就日期格式而言,这取决于存储在
startDate
endDate
中的内容

let curDate = new Date()
const List = await Routine.find({
                                 startDate:{"$lt":curDate},
                                 endDate:{"$gt":curDate}
                                })

请假设async/await语法维护正确。您可以使用
$lt
$gt
,我假设startDate和endDate是架构字段?很抱歉不提这一点。是的,'startDate'和'endDate'是架构字段@Karl Lb,但我不会直接与任何架构字段进行比较,因为'currentDate'不是架构字段。那么如何做到这一点呢@卡尔L