如何获得猫鼬的全部文件?

usermodel.find({ 'word': { $regex: `.*${word2}.*` } })
        .populate('user').limit(3)
        .skip(page).exec((err,searches) => {

})

使用限制并跳过时如何获取文档数(总数)? 当我使用猫鼬-分页时,它给了我总数 但是我怎么能在这里得到总数?

ziaiwo 回答:如何获得猫鼬的全部文件?

您可以使用$facet运行两个单独的查询:

usermodel.aggregate([
    { $match: { your query goes here } },{
        $facet: {
            filtered: [ { $limit: 3 } ],total: [ { $count: "total" } ]
        }
    },{
        $unwind: "$total"
    }
])
本文链接:https://www.f2er.com/2574580.html

大家都在问