javascript - Mongoose - What does the exec function do? -


i came across piece of mongoose code included query findone , exec() function.

ive never seen method in javascript before? exactly?

basically when using mongoose, documents can retrieved using helpers. every model method accepts query conditions can executed means of callback or exec method.

callback:

user.findone({ name: 'daniel' }, function (err, user) {   // }); 

exec:

user   .findone({ name: 'daniel' })   .exec(function (err, user) {       //   }); 

therefore when don't pass callback can build query , execute it.

you can find additional info in mongoose docs.

update

something note when using promises in combination mongoose async operations mongoose queries not promises. queries return thenable, if need real promise should use exec method. more information can found here.

during update noticed didn't explicitly answer question:

ive never seen method in javascript before? exactly?

well it's not native javascript method, part of mongoose api.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -