我有这个猫鼬模式。
var mongoose = require ('mongoose')
, dev = require ('../db').dev ();
var schema = new mongoose.Schema ({
date: {
type: Date,
default: Date.now
},
company: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Company'
},
questionnaire: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Questionnaire'
}
});
module.exports = dev.model ('Survey', schema);
我只想找到具有特定公司 ID 的调查。我怎么做?我试过(用我的 Express 处理程序):
app.get ('/survey', function (req, res) {
Survey.find ({ company: req.query.company }).populate ('questionnaire').exec (function (err, surveys) {
return res.json (surveys);
});
});