我怎样才能得到由特定的许可证ID在填充对象中创build的logging?

我有两个名为UserQuestion模型。

User模型具有license属性, Question模型具有created_by属性。

Questioncreated_by属性是对User模型的引用。

我怎样才能得到由license ID特定用户created_by问题?

我试试这个:

 QuestionResource .find({'created_by.license':req.query.license}) .exec(function (err, result) { if (err) res.json(err) else res.json(result) }) 

但似乎没有工作。

您可以使用.populate()方法的match选项,如下所示:

 QuestionResource .find() .populate({ path: 'created_by', match: { 'license': req.query.license } }) .exec(function (err, result) { if (err) res.json(err) var docs = result.filter(function(doc){ return doc.created_by.length; }); res.json(docs) })