Mongoose - What does the exec function do?
I came across a piece of Mongoose code that included a query findOne and then an exec() function.
I've never seen that method in Javascript before? What does it do exactly?
To understand the mongoose exec function basically when using mongoose, documents can be retrieved using helpers. Every model method that accepts query conditions can be executed by means of a callback or the exec method.
callback:
User.findOne({ name: 'daniel' }, function (err, user) {
//
});
exec:
User .findOne({ name: 'daniel' }) .exec(function (err, user) { //
});