mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
@types/mongoose: added save options
This commit is contained in:
Vendored
+16
-1
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user