猫鼬多字段选择不起作用



在下面的模式中,我试图用选定的字段来查找。结果,我只收到前两个组织名称和描述,但其他人没有收到。任何想法。我是猫鼬新手。我也无法从文件中找到任何原因。任何帮助都将不胜感激。

我的模式:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
let JobsSchema = new Schema ({
_id: {type:String, required: true, max:100},
sector: {type:String, required: true, max:100},
category: {type:String, required: true, max:100},
apply_mode: {type:String, required: true, max:100},
org_name: {type:String, required: true, max:100},
description: {type:String, required: true},
start_date: {type: Date},
end_date: {type: Date},
total_openings: {type: Number},
total_openings_description: {type:String},
min_salary: {type: Number},
max_salary: {type: Number},
salary_description: {type: String},
apply_steps: {type: String},
tags: [],
additional_dates: [{
additional_date_label: {type:String, required: true, max:100},
additional_date_value: {type:Date},
}],
age_limits: [{
age_limit_label: {type:String, required: true, max:100},
age_limit_min_value: {type: Number},
age_limit_max_value: {type: Number},
}],
application_fees: [{
application_fee_label: {type:String, required: true, max:100},
application_fee_value: {type: Number},
}],
url_links: [{
url_link_label: {type:String, required: true, max:100},
url_link_value: {type:String, required: true, max:100},
}]
},
{ collection: 'Jobs' }); // this line to match name in db
module.exports = mongoose.model('jobs', JobsSchema);

我的查询:

Job.find(
{},
"org_name description start_date end_date total_openings min_salary max_salary",
{ sort: { start_date: "asc" }, skip: pageNumber * pageSize, limit: pageSize },
(err, jobs) => {
if (err) {
res.render("error", {
errMsg: "issue in getting records. Try after sometime.",
errBody: err
});
}
if (jobs) {
res.render("listJob", {
jobs: jobs
});
}
}
);

结果

[
{
"_id": "Job1",
"org_name": "Test org",
"description": "<p>Test Desc</p><p><b>Hello world</b></p>"
},
{
"_id": "Job2",
"org_name": "Test org11",
"description": "<p>Test descr</p>"
},
{
"_id": "Job10",
"org_name": "Test inc 1",
"description": "<p>,smdfndfskj</p>"
}
]

我最终发现投影字段应该存在于所有文档中,然后只有它会应用。

最新更新