我想用猫鼬进行查询,该查询将根据用户键入的内容显示结果,但问题是,当用户开始输入日期(例如2019-08)以显示该日期的所有结果时,我如何进行查询我将猫鼬的属性类型从日期更改为字符串,但这不是解决问题的好方法,我尝试了在STACKOVERFLOW中发布的其他答案,但我没有成功。
所以我现在的查询是这样的:
ForeignEmployee.aggregate([
{
$lookup: {
from: "grouplists",
localField: "groupList",
foreignField: "_id",
as: "group"
}
},
{ $unwind: "$group" },
{
$lookup: {
from: "companies",
localField: "company",
foreignField: "_id",
as: "company"
}
},
{ $unwind: "$company" },
{
$match: {
$or: [
// { name: { $regex: findBy, $options: "i" } },
// { surname: { $regex: findBy, $options: "i" } },
// { username: { $regex: findBy, $options: "i" } },
// { role: { $regex: findBy, $options: "i" } },
// { zone: { $regex: findBy, $options: "i" } },
{
launchDate: {
$lt: new Date(findBy)
}
}
// { position: { $regex: findBy, $options: "i" } },
// { task: { $regex: findBy, $options: "i" } },
// { "group.generatedName": { $regex: findBy, $options: "i" } },
// { "group.date": { $regex: findBy, $options: "i" } },
// { "group.time": { $regex: findBy, $options: "i" } },
// { "company.company": { $regex: findBy, $options: "i" } }
]
}
},
{
$project: {
name: 1,
surname: 1,
username: 1,
role: 1,
zone: 1,
launchDate: 1,
position: 1,
task: 1,
company: 1,
group: 1
}
}
])