I've been learning nodejs for the last couple of days and I stumbled upon something that I can't find any good explanations to.
Basically it's about exec
vs a normal callback, i.e. (err, res) => {}
, like this:
Product.find({}).exec((err, products) => {});
Product.find({}, (err, products) => {});
I find more examples that use exec
, but when I read about exec
I can't really understand why. They both seem to be doing the same thing to me.
So, my question is, should I be using one over the other, and if so, why?
EDIT:
Just to make things clear, Product
is a MongoDB model/schema. Like this:
const Product = mongoose.model('Product', new Schema({
title: {type: String, default: ''},
description: {type: String, default: ''},
price: {type: Number, default: ''}
}));