From c5b235537e8888fd04d2928ec550f206b53fd8e7 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 26 Sep 2019 22:50:24 -0700 Subject: [PATCH] docs(promises): add note about queries being thenable Fix #8110 --- test/docs/promises.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/docs/promises.test.js b/test/docs/promises.test.js index d798b14bd84..3a96d2ca835 100644 --- a/test/docs/promises.test.js +++ b/test/docs/promises.test.js @@ -84,6 +84,21 @@ describe('promises docs', function () { }); }); + /** + * Although queries are not promises, queries are [thenables](https://promisesaplus.com/#terminology). + * That means they have a `.then()` function, so you can use queries as promises with either + * promise chaining or [async await](https://asyncawait.net) + */ + it('Queries are thenable', function (done) { + Band.findOne({name: "Guns N' Roses"}).then(function(doc) { + // use doc + // acquit:ignore:start + assert.ok(!doc); + done(); + // acquit:ignore:end + }); + }); + /** * If you're an advanced user, you may want to plug in your own promise * library like [bluebird](https://www.npmjs.com/package/bluebird). Just set