Function set

  • Sets mongoose options

    Type Parameters

    Parameters

    Returns mongoose.Mongoose

  • Parameters

    • options: {
          allowDiskUse?: boolean;
          applyPluginsToChildSchemas?: boolean;
          applyPluginsToDiscriminators?: boolean;
          autoCreate?: boolean;
          autoIndex?: boolean;
          bufferCommands?: boolean;
          bufferTimeoutMS?: number;
          cloneSchemas?: boolean;
          createInitialConnection?: boolean;
          debug?: boolean | Writable | {
              color?: boolean;
              shell?: boolean;
          } | ((collectionName, methodName, ...methodArgs) => void);
          id?: boolean;
          maxTimeMS?: number;
          objectIdGetter?: boolean;
          overwriteModels?: boolean;
          returnOriginal?: boolean;
          runValidators?: boolean;
          sanitizeFilter?: boolean;
          sanitizeProjection?: boolean;
          selectPopulatedPaths?: boolean;
          setDefaultsOnInsert?: boolean;
          strict?: boolean | "throw";
          strictPopulate?: boolean;
          strictQuery?: boolean | "throw";
          timestamps.createdAt.immutable?: boolean;
          toJSON?: ToObjectOptions<mongoose.Document<unknown, {}, unknown> & Required<{
              _id: unknown;
          }>>;
          toObject?: ToObjectOptions<mongoose.Document<unknown, {}, unknown> & Required<{
              _id: unknown;
          }>>;
          transactionAsyncLocalStorage?: boolean;
          translateAliases?: boolean;
      }
      • Optional allowDiskUse?: boolean

        Set to true to set allowDiskUse to true to all aggregation operations by default.

        Default

        false
        
      • Optional applyPluginsToChildSchemas?: boolean

        Set to false to skip applying global plugins to child schemas.

        Default

        true
        
      • Optional applyPluginsToDiscriminators?: boolean

        Set 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.

        Default

        false
        
      • Optional autoCreate?: boolean

        autoCreate 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 autoIndex?: boolean

        Set to false to disable automatic index creation for all models associated with this Mongoose instance.

        Default

        true
        
      • Optional bufferCommands?: boolean

        enable/disable mongoose's buffering mechanism for all connections and models.

        Default

        true
        
      • Optional bufferTimeoutMS?: number

        If 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).

        Default

        10000
        
      • Optional cloneSchemas?: boolean

        Set to true to clone() all schemas before compiling into a model.

        Default

        false
        
      • Optional createInitialConnection?: boolean

        Set to false to disable the creation of the initial default connection.

        Default

        true
        
      • Optional debug?: boolean | Writable | {
            color?: boolean;
            shell?: boolean;
        } | ((collectionName, methodName, ...methodArgs) => void)

        If 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(', ')}).

        Default

        false
        
      • Optional id?: boolean

        If true, adds a id virtual to all schemas unless overwritten on a per-schema basis.

        Default Value

        true
        
      • Optional maxTimeMS?: number

        If set, attaches maxTimeMS to every query

      • Optional objectIdGetter?: boolean

        Mongoose adds a getter to MongoDB ObjectId's called _id that returns this for convenience with populate. Set this to false to remove the getter.

        Default

        true
        
      • Optional overwriteModels?: boolean

        Set to true to default to overwriting models with the same name when calling mongoose.model(), as opposed to throwing an OverwriteModelError.

        Default

        false
        
      • Optional returnOriginal?: boolean

        If 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.

        Default

        true
        
      • Optional runValidators?: boolean

        Set to true to enable update validators for all validators by default.

        Default

        false
        
      • Optional sanitizeFilter?: boolean

        Sanitizes query filters against query selector injection attacks by wrapping any nested objects that have a property whose name starts with $ in a $eq.

      • Optional sanitizeProjection?: boolean
      • Optional selectPopulatedPaths?: boolean

        Set to false to opt out of Mongoose adding all fields that you populate() to your select(). The schema-level option selectPopulatedPaths overwrites this one.

        Default

        true
        
      • Optional setDefaultsOnInsert?: boolean

        Mongoose 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.

        Default

        true
        
      • Optional strict?: boolean | "throw"

        Sets the default strict mode for schemas. May be false, true, or 'throw'.

        Default

        true
        
      • Optional strictPopulate?: boolean

        Set to false to allow populating paths that aren't in the schema.

        Default

        true
        
      • Optional strictQuery?: boolean | "throw"

        Sets the default strictQuery mode for schemas. May be false, true, or 'throw'.

        Default

        false
        
      • Optional timestamps.createdAt.immutable?: boolean

        If false, it will change the createdAt field to be immutable: false which means you can update the createdAt.

        Default

        true
        
      • Optional toJSON?: ToObjectOptions<mongoose.Document<unknown, {}, unknown> & Required<{
            _id: unknown;
        }>>

        Overwrites default objects to toJSON(), for determining how Mongoose documents get serialized by JSON.stringify()

        Default

        { transform: true, flattenDecimals: true }
        
      • Optional toObject?: ToObjectOptions<mongoose.Document<unknown, {}, unknown> & Required<{
            _id: unknown;
        }>>

        Overwrites default objects to toObject()

        Default

        { transform: true, flattenDecimals: true }
        
      • Optional transactionAsyncLocalStorage?: boolean

        Set 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 translateAliases?: boolean

        If true, convert any aliases in filter, projection, update, and distinct to their database property names. Defaults to false.

    Returns mongoose.Mongoose

Generated using TypeDoc