📝 Josh's Notes

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:

1usersModel.find({ groupName: "admin" })
2.then((group) => {
3	console.log(group)
4})

However, adding exec will execute the query.

1usersModel.find({ groupName: "admin" }).exec()
2.then((group) => {
3	console.log(group)
4})

#mongodb #javascript #mongoose