Abdullah
Abdullah

Reputation: 23

Mongoose: populate after query

How to i populate the query result after query in mongoose like this:

users
        .find({name:"doejohn"})
        .skip(3)
        .limit(9)
        .exec((err,user) => {
            user // result
                .populate("tweets")
                .exec(callback)
})
        })

Upvotes: 0

Views: 140

Answers (2)

Ahmad headr
Ahmad headr

Reputation: 41

It's simple:

users.findOne({username:"doejohn"})
    .skip(3)
    .populate("tweets"," Columns name ")
    .exec((err,user) => {})

you can read the docs of populate in mongoose here:

https://mongoosejs.com/docs/populate.html

Upvotes: 1

Jeremy Thille
Jeremy Thille

Reputation: 26370

Simply like this :

users.findOne({username:"doejohn"})
        .skip(3)
        .populate("tweets")
        .exec((err,user) => {})

.limit(9) is useless, because you're using .findOne()

Upvotes: 1

Related Questions