如何只拉取 6 个文档并且在一个字段中的值为 true?

How pull only 6 documents and with the value true in a field?

我有这个控制器:

Model.find().sort('date').limit(6).exec(function(error, result) {
    if (error) {
        console.log(error);
    }
    else {
      res.send(result);
    }
});

在我的架构中,我有一个 tof 字段(true 或 false),我只想在 tof 字段中提取 6 个值为 true 的文档,这可能吗?

你试过了吗

Model.find({tof: true}).sort('date').limit(6)

您可以使用 select 条件,例如 >

Model.find({'tof':true}).sort('date').limit(6).exec(function(error, result) {
    if (error) {
        console.log(error);
    }
    else {
        res.send(result);
    }
});