@types/mongoose: added save options

This commit is contained in:
Fábio Batista
2017-04-07 19:51:54 -03:00
parent d005e9bd51
commit 0903e768fe
2 changed files with 21 additions and 2 deletions
+16 -1
View File
@@ -2550,7 +2550,7 @@ declare module "mongoose" {
* @param options.validateBeforeSave set to false to save without validating.
* @param fn optional callback
*/
save(fn?: (err: any, product: this, numAffected: number) => void): Promise<this>;
save(options?: SaveOptions, fn?: (err: any, product: this, numAffected: number) => void): Promise<this>;
/**
* Version using default version key. See http://mongoosejs.com/docs/guide.html#versionKey
@@ -2559,6 +2559,21 @@ declare module "mongoose" {
__v?: number;
}
interface SaveOptions {
safe?: boolean | WriteConcern;
validateBeforeSave?: boolean;
}
interface WriteConcern {
j?: boolean;
w?: number | 'majority' | TagSet;
wtimeout?: number;
}
interface TagSet {
[k: string]: string;
}
interface ModelProperties {
/** Base Mongoose instance the model uses. */
base: typeof mongoose;
+5 -1
View File
@@ -1050,7 +1050,7 @@ aggregate.unwind(
includeArrayIndex: "idx",
preserveNullAndEmptyArrays: true
});
/*
* section schematype.js
* http://mongoosejs.com/docs/api.html#schematype-js
@@ -1215,6 +1215,10 @@ MongoModel.find({}).$where('indexOf("val") !== -1').exec(function (err, docs) {
MongoModel.findById(999, function (err, doc) {
doc.increment();
doc.save(cb).then(cb).catch(cb);
doc.save({ validateBeforeSave: false }, cb).then(cb).catch(cb);
doc.save({ safe: true }, cb).then(cb).catch(cb);
doc.save({ safe: { w: 2, j: true } }, cb).then(cb).catch(cb);
doc.save({ safe: { w: 'majority', wtimeout: 10000 } }, cb).then(cb).catch(cb);
});
MongoModel = (new MongoModel()).model('MongoModel');
var mongoModel = new MongoModel();