Mongoose Notes
exec()
The exec function (stands for execute) can be used on a Query object to⦠execute the Query. For example. The following code does not actually execute the query. It just returns a Mongoose Query object and, therefore, will log out undefined:
usersModel.find({ groupName: "admin" })
.then((group) => {
console.log(group)
})
However, adding exec will execute the query.
usersModel.find({ groupName: "admin" }).exec()
.then((group) => {
console.log(group)
})