【发布时间】:2020-07-31 09:38:41
【问题描述】:
我只想在 Mongoose find() 中设置一些条件来从我的 Routine 模型中查询。有没有可能?或者如何设置这种自定义条件?
const List = await Routine.find({
$where:
() => {
moment(currentDate).isBetween(this.startDate, this.endDate, undefined, '[]') == true &&
customFunc(this) == true
}
})
customFunc() 返回一个布尔值
【问题讨论】:
-
请假设 async/await 语法维护得当
-
你可以使用
$lt和$gt,我假设startDate和endDate是模式字段? -
抱歉没有提及。是的 'startDate' 和 'endDate' 是架构字段@Karl L
-
但我没有直接与任何模式字段进行比较,因为“currentDate”不是模式字段。那么如何完成呢? @Karl L
标签: node.js mongoose mongoose-schema