Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

node.js - I get error when trying to filter mongoose data using NodeJs

I am trying to filter and paginate data from my API, but I keep getting an error. here is the code I am trying to use to achieve that.

router.get('/api/place', async (req, res) => {
    //  pagination and filter
    // const match = {}

    const noOnPage = parseInt(req.query.limit) || 10
    const pageNo = (parseInt(req.query.page)-1)*parseInt(req.query.limit)

    try {
        const place = await Place.find({
            isOpen: true
        })
        .populate({
            select: '-media',
            match,
            options: {
                limit: noOnPage,
                skip: pageNo
            }
        })
        .exec()

        console.log("hello");
        res.status(200).send(place)
    } catch (e) {
        res.status(500).send()
    }
})

please what could I be missing?

question from:https://stackoverflow.com/questions/65919510/i-get-error-when-trying-to-filter-mongoose-data-using-nodejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

remove match and set path argument with name of field that has ref

       const place = await Place.find({
            isOpen: true
        })
        .populate({
            path: 'user',
            select: '-media',
            options: {
                limit: noOnPage,
                skip: pageNo
            }
        })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...