mongoose 7.2.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -181,17 +181,13 @@ Once we have our model, we can then instantiate it, and save it:
181
181
  ```js
182
182
  const instance = new MyModel();
183
183
  instance.my.key = 'hello';
184
- instance.save(function(err) {
185
- //
186
- });
184
+ await instance.save();
187
185
  ```
188
186
 
189
187
  Or we can find documents from the same collection
190
188
 
191
189
  ```js
192
- MyModel.find({}, function(err, docs) {
193
- // docs.forEach
194
- });
190
+ await MyModel.find({});
195
191
  ```
196
192
 
197
193
  You can also `findOne`, `findById`, `update`, etc.
@@ -208,8 +204,8 @@ For more details check out [the docs](http://mongoosejs.com/docs/queries.html).
208
204
  ```js
209
205
  const conn = mongoose.createConnection('your connection string');
210
206
  const MyModel = conn.model('ModelName', schema);
211
- const m = new MyModel;
212
- m.save(); // works
207
+ const m = new MyModel();
208
+ await m.save(); // works
213
209
  ```
214
210
 
215
211
  vs
@@ -217,8 +213,8 @@ vs
217
213
  ```js
218
214
  const conn = mongoose.createConnection('your connection string');
219
215
  const MyModel = mongoose.model('ModelName', schema);
220
- const m = new MyModel;
221
- m.save(); // does not work b/c the default connection object was never connected
216
+ const m = new MyModel();
217
+ await m.save(); // does not work b/c the default connection object was never connected
222
218
  ```
223
219
 
224
220
  ### Embedded Documents
@@ -241,25 +237,18 @@ const post = new BlogPost();
241
237
  // create a comment
242
238
  post.comments.push({ title: 'My comment' });
243
239
 
244
- post.save(function(err) {
245
- if (!err) console.log('Success!');
246
- });
240
+ await post.save();
247
241
  ```
248
242
 
249
243
  The same goes for removing them:
250
244
 
251
245
  ```js
252
- BlogPost.findById(myId, function(err, post) {
253
- if (!err) {
254
- post.comments[0].remove();
255
- post.save(function(err) {
256
- // do something
257
- });
258
- }
259
- });
246
+ const post = await BlogPost.findById(myId);
247
+ post.comments[0].deleteOne();
248
+ await post.save();
260
249
  ```
261
250
 
262
- Embedded documents enjoy all the same features as your models. Defaults, validators, middleware. Whenever an error occurs, it's bubbled to the `save()` error callback, so error handling is a snap!
251
+ Embedded documents enjoy all the same features as your models. Defaults, validators, middleware.
263
252
 
264
253
 
265
254
  ### Middleware