S
S
Stanislav2017-12-30 02:41:09
Node.js
Stanislav, 2017-12-30 02:41:09

What is the difference when accessing a collection then() or .exec()?

Works both and everything together

Coll.find().exec()
Coll.find().then()
Coll.find().exec().then()

What is the difference and which is better to use?
In cases with such a sample, everything is clear
Coll.find().then(/**blablabla**/).catch(/**throw**/)

But it can also be done like this
Coll.find().exec().then(/**blablabla**/).catch(/**throw**/)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2017-12-30
@ms-dred

Just short for I do it myself.

then(thenFn, catchFn) {
  return Promise.resolve(this.run()).then(thenFn, catchFn);
}

Here is the request code from the library
Query.prototype.then = function(resolve, reject) {
  return this.exec().then(resolve, reject);
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question