当我想要查询人口时,我没什么问题。
var userSchema = new Schema({
id: { type: Number, required: true },
firstName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true },
phone: { type: String, required: true },
password: { type: String, required: true },
created_at: { type: Date, default: Date.now },
projects: [{
project: { type: Schema.Types.ObjectId, ref: 'Project' },
duty: { type: Schema.Types.ObjectId, ref: 'Duty' },
valid: { type: Number, required: true },
}],
});
我想检查所有项目的“有效”是否为1或0。
这是我的控制者:
list: function list(req, res) {
User.findOne({id: req.session.user.id}).select('projects')
.populate('projects.project').where('projects.valid', 0).exec(function(err, usr) {
if (err) return handleError(err);
return res.json(usr);
});
},
但它返回给我所有项目,而不仅仅是有效值为0的项目。 你觉得为什么? (我是初学者,没有sql数据库)
谢谢! 祝你有个美好的一天