我想基于不超过45天的日期获取数据。我正在使用汇总,并且有一个列postdate,所以我只想在postdate在45天内获得数据。
以下代码发布日期为列名:
const baseStages = [
{
$lookup: {
from: CrewbiesJobs.collection.name,
localField: "jobId",
foreignField: "jobId",
as: "job_docs"
}
},
{
$unwind: "$job_docs"
},
{
$project: {
_id: 1,
jobTitle: 1,
jobId: 1,
// jobDescription: 1,
postedDate: 1,
filter1: 1,
filter2: 1,
filter3: 1,
createdAt: 1,
updatedAt: 1
}
},
{ $match: filter },
{ $sort: { postedDate: -1 } }
];
const jobsStages = [
...baseStages,
{ $skip: query.skip },
{ $limit: query.limit }
];
let jobsAggregate = await Jobs.aggregate(jobsStages);
这是我的猫鼬模式:
let jobsSchema = new mongoose.Schema(
{
jobTitle: String,
jobId: {
type: Schema.Types.String,
unique: true,
dropDups: true,
ref: "Jobs"
},
jobDescription: String,
postedDate: String,
filter1: [{ label: String, value: String }],
filter2: [{ label: String, value: String }],
filter3: [{ label: String, value: String }]
},
{ timestamps: true }
);