Skip to content

Commit

Permalink
docs(model): make create() docs use async/await, and add another wa…
Browse files Browse the repository at this point in the history
…rning about how `create()` with options requires array syntax

Fix #9280
  • Loading branch information
vkarpov15 committed Jul 26, 2020
1 parent 66f1fd9 commit ffdfe88
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2948,26 +2948,16 @@ Model.findByIdAndRemove = function(id, options, callback) {
*
* ####Example:
*
* // pass a spread of docs and a callback
* Candy.create({ type: 'jelly bean' }, { type: 'snickers' }, function (err, jellybean, snickers) {
* if (err) // ...
* });
*
* // pass an array of docs
* var array = [{ type: 'jelly bean' }, { type: 'snickers' }];
* Candy.create(array, function (err, candies) {
* if (err) // ...
*
* var jellybean = candies[0];
* var snickers = candies[1];
* // ...
* });
*
* // callback is optional; use the returned promise if you like:
* var promise = Candy.create({ type: 'jawbreaker' });
* promise.then(function (jawbreaker) {
* // ...
* })
* // Insert one new `Character` document
* await Character.create({ name: 'Jean-Luc Picard' });
*
* // Insert multiple new `Character` documents
* await Character.create([{ name: 'Will Riker' }, { name: 'Geordi LaForge' }]);
*
* // Create a new character within a transaction. Note that you **must**
* // pass an array as the first parameter to `create()` if you want to
* // specify options.
* await Character.create([{ name: 'Jean-Luc Picard' }], { session });
*
* @param {Array|Object} docs Documents to insert, as a spread or array
* @param {Object} [options] Options passed down to `save()`. To specify `options`, `docs` **must** be an array, not a spread.
Expand Down

0 comments on commit ffdfe88

Please sign in to comment.