Optional
allowfalse
Optional
applySet to false
to skip applying global plugins to child schemas.
true
Optional
applySet to true
to apply global plugins to discriminator schemas.
This typically isn't necessary because plugins are applied to the base schema and
discriminators copy all middleware, methods, statics, and properties from the base schema.
false
Optional
autoautoCreate is true
by default unless readPreference is secondary or secondaryPreferred,
which means Mongoose will attempt to create every model's underlying collection before
creating indexes. If readPreference is secondary or secondaryPreferred, Mongoose will
default to false for both autoCreate and autoIndex because both createCollection() and
createIndex() will fail when connected to a secondary.
Optional
autoSet to false
to disable automatic index creation for all models associated with this Mongoose instance.
true
Optional
bufferenable/disable mongoose's buffering mechanism for all connections and models.
true
Optional
bufferIf bufferCommands is on, this option sets the maximum amount of time Mongoose buffering will wait before throwing an error. If not specified, Mongoose will use 10000 (10 seconds).
10000
Optional
cloneSet to true
to clone()
all schemas before compiling into a model.
false
Optional
createSet to false
to disable the creation of the initial default connection.
true
Optional
debugIf true
, prints the operations mongoose sends to MongoDB to the console.
If a writable stream is passed, it will log to that stream, without colorization.
If a callback function is passed, it will receive the collection name, the method
name, then all arguments passed to the method. For example, if you wanted to
replicate the default logging, you could output from the callback
Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})
.
Optional
color?: booleanOptional
shell?: booleanRest
...methodArgs: any[]Rest
false
Optional
idIf true
, adds a id
virtual to all schemas unless overwritten on a per-schema basis.
true
Optional
maxIf set, attaches maxTimeMS to every query
Optional
objectMongoose adds a getter to MongoDB ObjectId's called _id
that
returns this
for convenience with populate. Set this to false to remove the getter.
true
Optional
overwriteSet to true
to default to overwriting models with the same name when calling
mongoose.model()
, as opposed to throwing an OverwriteModelError
.
false
Optional
returnIf false
, changes the default returnOriginal
option to findOneAndUpdate()
,
findByIdAndUpdate
, and findOneAndReplace()
to false. This is equivalent to
setting the new
option to true
for findOneAndX()
calls by default. Read our
findOneAndUpdate()
tutorial
for more information.
true
Optional
runSet to true to enable update validators for all validators by default.
false
Optional
sanitizeSanitizes query filters against query selector injection attacks by wrapping any nested objects that have a property whose name starts with $ in a $eq.
Optional
sanitizeOptional
selectSet to false to opt out of Mongoose adding all fields that you populate()
to your select()
. The schema-level option selectPopulatedPaths
overwrites this one.
true
Optional
setMongoose also sets defaults on update() and findOneAndUpdate() when the upsert option is set by adding your schema's defaults to a MongoDB $setOnInsert operator. You can disable this behavior by setting the setDefaultsOnInsert option to false.
true
Optional
strictSets the default strict mode for schemas.
May be false
, true
, or 'throw'
.
true
Optional
strictSet to false
to allow populating paths that aren't in the schema.
true
Optional
strictSets the default strictQuery mode for schemas.
May be false
, true
, or 'throw'
.
false
Optional
timestamps.createdIf false
, it will change the createdAt
field to be immutable: false
which means you can update the createdAt
.
true
Optional
toJSONOverwrites default objects to toJSON()
, for determining how Mongoose
documents get serialized by JSON.stringify()
{ transform: true, flattenDecimals: true }
Optional
toOverwrites default objects to toObject()
{ transform: true, flattenDecimals: true }
Optional
transactionSet to true to make Mongoose use Node.js' built-in AsyncLocalStorage (Added in: v13.10.0, v12.17.0; Stable since 16.4.0)
to set session
option on all operations within a connection.transaction(fn)
call
by default. Defaults to false.
Optional
translateIf true
, convert any aliases in filter, projection, update, and distinct
to their database property names. Defaults to false.
Generated using TypeDoc
Set to
true
to setallowDiskUse
to true to all aggregation operations by default.