Skip to content

Commit

Permalink
docs(document): fix formatting on getChanges()
Browse files Browse the repository at this point in the history
Fix #9376
  • Loading branch information
vkarpov15 committed Sep 5, 2020
1 parent 5cd10cf commit 167402c
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions lib/document.js
Expand Up @@ -3975,32 +3975,41 @@ Document.prototype.$__fullPath = function(path) {
* Returns the changes that happened to the document
* in the format that will be sent to MongoDB.
*
* ###Example:
* const userSchema = new Schema({
* name: String,
* age: Number,
* country: String
* });
* const User = mongoose.model('User', userSchema);
* const user = await User.create({
* name: 'Hafez',
* age: 25,
* country: 'Egypt'
* });
* #### Example:
*
* // returns an empty object, no changes happened yet
* user.getChanges(); // { }
* const userSchema = new Schema({
* name: String,
* age: Number,
* country: String
* });
* const User = mongoose.model('User', userSchema);
* const user = await User.create({
* name: 'Hafez',
* age: 25,
* country: 'Egypt'
* });
*
* // returns an empty object, no changes happened yet
* user.getChanges(); // { }
*
* user.country = undefined;
* user.age = 26;
*
* user.country = undefined;
* user.age = 26;
* user.getChanges(); // { $set: { age: 26 }, { $unset: { country: 1 } } }
*
* user.getChanges(); // { $set: { age: 26 }, { $unset: { country: 1 } } }
* await user.save();
*
* await user.save();
* user.getChanges(); // { }
*
* user.getChanges(); // { }
* Modifying the object that `getChanges()` returns does not affect the document's
* change tracking state. Even if you `delete user.getChanges().$set`, Mongoose
* will still send a `$set` to the server.
*
* @return {Object} changes
* @return {Object}
* @api public
* @method getChanges
* @memberOf Document
* @instance
*/

Document.prototype.getChanges = function() {
Expand Down

0 comments on commit 167402c

Please sign in to comment.