Merge pull request #13859 from Snorremd/master

Fix: Change MongooseDocument.set() return type from void to this.
See http://mongoosejs.com/docs/api.html#document_Document-set

Modify doc.set() examples in test file to chain the set method in
order to test the "this" return type.
This commit is contained in:
Sheetal Nandi
2017-01-10 15:51:08 -08:00
committed by GitHub
2 changed files with 5 additions and 8 deletions
+3 -3
View File
@@ -1010,9 +1010,9 @@ declare module "mongoose" {
* @param type optionally specify a type for "on-the-fly" attributes
* @param options optionally specify options that modify the behavior of the set
*/
set(path: string, val: any, options?: Object): void;
set(path: string, val: any, type: any, options?: Object): void;
set(value: Object): void;
set(path: string, val: any, options?: Object): this;
set(path: string, val: any, type: any, options?: Object): this;
set(value: Object): this;
/**
* The return value of this method is used in calls to JSON.stringify(doc).
+2 -5
View File
@@ -449,10 +449,7 @@ doc.populate(function (err, doc) {
});
});
doc.populated('path');
doc.set('path', 999, {});
doc.set({
path: 999
});
doc.set('path', 999, {}).set({ path: 999 });
doc.toJSON({
getters: true,
virtuals: false
@@ -1494,4 +1491,4 @@ const extended: mongoose.Model<extended> = base.discriminator<extended>('extende
const x = new extended({
username: 'hi', // required in baseSchema
email: 'beddiw', // required in extededSchema
});
});