UNPKG

6.46 kBTypeScriptView Raw
1declare module 'mongoose' {
2 import stream = require('stream');
3
4 interface MongooseOptions {
5 /**
6 * Set to `true` to set `allowDiskUse` to true to all aggregation operations by default.
7 *
8 * @default false
9 */
10 allowDiskUse?: boolean;
11 /**
12 * Set to `false` to skip applying global plugins to child schemas.
13 *
14 * @default true
15 */
16 applyPluginsToChildSchemas?: boolean;
17
18 /**
19 * Set to `true` to apply global plugins to discriminator schemas.
20 * This typically isn't necessary because plugins are applied to the base schema and
21 * discriminators copy all middleware, methods, statics, and properties from the base schema.
22 *
23 * @default false
24 */
25 applyPluginsToDiscriminators?: boolean;
26
27 /**
28 * autoCreate is `true` by default unless readPreference is secondary or secondaryPreferred,
29 * which means Mongoose will attempt to create every model's underlying collection before
30 * creating indexes. If readPreference is secondary or secondaryPreferred, Mongoose will
31 * default to false for both autoCreate and autoIndex because both createCollection() and
32 * createIndex() will fail when connected to a secondary.
33 */
34 autoCreate?: boolean;
35
36 /**
37 * Set to `false` to disable automatic index creation for all models associated with this Mongoose instance.
38 *
39 * @default true
40 */
41 autoIndex?: boolean;
42
43 /**
44 * enable/disable mongoose's buffering mechanism for all connections and models.
45 *
46 * @default true
47 */
48 bufferCommands?: boolean;
49
50 /**
51 * If bufferCommands is on, this option sets the maximum amount of time Mongoose
52 * buffering will wait before throwing an error.
53 * If not specified, Mongoose will use 10000 (10 seconds).
54 *
55 * @default 10000
56 */
57 bufferTimeoutMS?: number;
58
59 /**
60 * Set to `true` to `clone()` all schemas before compiling into a model.
61 *
62 * @default false
63 */
64 cloneSchemas?: boolean;
65
66 /**
67 * If `true`, prints the operations mongoose sends to MongoDB to the console.
68 * If a writable stream is passed, it will log to that stream, without colorization.
69 * If a callback function is passed, it will receive the collection name, the method
70 * name, then all arguments passed to the method. For example, if you wanted to
71 * replicate the default logging, you could output from the callback
72 * `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
73 *
74 * @default false
75 */
76 debug?:
77 | boolean
78 | { color?: boolean; shell?: boolean; }
79 | stream.Writable
80 | ((collectionName: string, methodName: string, ...methodArgs: any[]) => void);
81
82 /**
83 * If `true`, adds a `id` virtual to all schemas unless overwritten on a per-schema basis.
84 * @defaultValue true
85 */
86 id?: boolean;
87
88 /**
89 * If `false`, it will change the `createdAt` field to be [`immutable: false`](https://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-immutable)
90 * which means you can update the `createdAt`.
91 *
92 * @default true
93 */
94 'timestamps.createdAt.immutable'?: boolean
95
96 /** If set, attaches [maxTimeMS](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/) to every query */
97 maxTimeMS?: number;
98
99 /**
100 * Mongoose adds a getter to MongoDB ObjectId's called `_id` that
101 * returns `this` for convenience with populate. Set this to false to remove the getter.
102 *
103 * @default true
104 */
105 objectIdGetter?: boolean;
106
107 /**
108 * Set to `true` to default to overwriting models with the same name when calling
109 * `mongoose.model()`, as opposed to throwing an `OverwriteModelError`.
110 *
111 * @default false
112 */
113 overwriteModels?: boolean;
114
115 /**
116 * If `false`, changes the default `returnOriginal` option to `findOneAndUpdate()`,
117 * `findByIdAndUpdate`, and `findOneAndReplace()` to false. This is equivalent to
118 * setting the `new` option to `true` for `findOneAndX()` calls by default. Read our
119 * `findOneAndUpdate()` [tutorial](https://mongoosejs.com/docs/tutorials/findoneandupdate.html)
120 * for more information.
121 *
122 * @default true
123 */
124 returnOriginal?: boolean;
125
126 /**
127 * Set to true to enable [update validators](
128 * https://mongoosejs.com/docs/validation.html#update-validators
129 * ) for all validators by default.
130 *
131 * @default false
132 */
133 runValidators?: boolean;
134
135 /**
136 * Sanitizes query filters against [query selector injection attacks](
137 * https://thecodebarbarian.com/2014/09/04/defending-against-query-selector-injection-attacks.html
138 * ) by wrapping any nested objects that have a property whose name starts with $ in a $eq.
139 */
140 sanitizeFilter?: boolean;
141
142 sanitizeProjection?: boolean;
143
144 /**
145 * Set to false to opt out of Mongoose adding all fields that you `populate()`
146 * to your `select()`. The schema-level option `selectPopulatedPaths` overwrites this one.
147 *
148 * @default true
149 */
150 selectPopulatedPaths?: boolean;
151
152 /**
153 * Mongoose also sets defaults on update() and findOneAndUpdate() when the upsert option is
154 * set by adding your schema's defaults to a MongoDB $setOnInsert operator. You can disable
155 * this behavior by setting the setDefaultsOnInsert option to false.
156 *
157 * @default true
158 */
159 setDefaultsOnInsert?: boolean;
160
161 /**
162 * Sets the default strict mode for schemas.
163 * May be `false`, `true`, or `'throw'`.
164 *
165 * @default true
166 */
167 strict?: boolean | 'throw';
168
169 /**
170 * Set to `false` to allow populating paths that aren't in the schema.
171 *
172 * @default true
173 */
174 strictPopulate?: boolean;
175
176 /**
177 * Sets the default [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
178 * May be `false`, `true`, or `'throw'`.
179 *
180 * @default false
181 */
182 strictQuery?: boolean | 'throw';
183
184 /**
185 * Overwrites default objects to `toJSON()`, for determining how Mongoose
186 * documents get serialized by `JSON.stringify()`
187 *
188 * @default { transform: true, flattenDecimals: true }
189 */
190 toJSON?: ToObjectOptions;
191
192 /**
193 * Overwrites default objects to `toObject()`
194 *
195 * @default { transform: true, flattenDecimals: true }
196 */
197 toObject?: ToObjectOptions;
198 }
199}
200
\No newline at end of file