Is exexPopulate() method is deprecated from the mongoose new version?

838 Views Asked by At
main()

    const main = async () =>{
    const task = await Task.findById('614ac31e103d9c5329d38686')
    await task.populate('owner').execPopulate()
    console.log(task.owner)
}

execPopulate() is not a function

2

There are 2 best solutions below

0
Francis.TM On BEST ANSWER

From changelogs at https://mongoosejs.com/docs/migrating_to_6.html#removed-execpopulate,

the line should be replaced to

await task.populate('owner')
0
Tabot Charles Bessong On

execPopulate() has been removed in latest version of mongoose , the code can only work if using oder version which is not advisable due to deprecation

Just remove the execPopulate and keep task.populate('owner')