Merge pull request #23573 from jendrikw/mongoose-strict-schema-option

mongoose: add 'throw' to the strict option for schemas
This commit is contained in:
Daniel Rosenwasser
2018-02-12 16:04:23 -08:00
committed by GitHub
2 changed files with 4 additions and 2 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
// Type definitions for Mongoose 5.0.1
// Project: http://mongoosejs.com/
// Definitions by: simonxca <https://github.com/simonxca>, horiuchi <https://github.com/horiuchi>, sindrenm <https://github.com/sindrenm>, lukasz-zak <https://github.com/lukasz-zak>, Alorel <https://github.com/Alorel>
// Definitions by: simonxca <https://github.com/simonxca>, horiuchi <https://github.com/horiuchi>, sindrenm <https://github.com/sindrenm>, lukasz-zak <https://github.com/lukasz-zak>, Alorel <https://github.com/Alorel>, jendrikw <https://github.com/jendrikw>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -722,7 +722,7 @@ declare module "mongoose" {
/** defaults to null */
shardKey?: boolean;
/** defaults to true */
strict?: boolean;
strict?: boolean | 'throw';
/** no default */
toJSON?: DocumentToObjectOptions;
/** no default */
+2
View File
@@ -432,6 +432,8 @@ new mongoose.Schema({
}
});
new mongoose.Schema({foo: String}, {strict: 'throw'});
export default function(schema: mongoose.Schema) {
schema.pre('init', function(this: mongoose.Document, next: (err?: Error) => void): void {
console.log('success!');