Interface ToObjectOptions<THydratedDocumentType>

interface ToObjectOptions<THydratedDocumentType> {
    aliases?: boolean;
    depopulate?: boolean;
    flattenMaps?: boolean;
    flattenObjectIds?: boolean;
    getters?: boolean;
    minimize?: boolean;
    transform?: boolean | ((doc, ret, options) => any);
    useProjection?: boolean;
    versionKey?: boolean;
    virtuals?: boolean | string[];
}

Type Parameters

Properties

aliases?: boolean

if options.virtuals = true, you can set options.aliases = false to skip applying aliases. This option is a no-op if options.virtuals = false.

depopulate?: boolean

if true, replace any conventionally populated paths with the original id in the output. Has no affect on virtual populated paths.

flattenMaps?: boolean

if true, convert Maps to POJOs. Useful if you want to JSON.stringify() the result of toObject().

flattenObjectIds?: boolean

if true, convert any ObjectIds in the result to 24 character hex strings.

getters?: boolean

apply all getters (path and virtual getters)

minimize?: boolean

remove empty objects (defaults to true)

transform?: boolean | ((doc, ret, options) => any)

if set, mongoose will call this function to allow you to transform the returned object

Type declaration

useProjection?: boolean

If true, omits fields that are excluded in this document's projection. Unless you specified a projection, this will omit any field that has select: false in the schema.

versionKey?: boolean

if false, exclude the version key (__v by default) from the output

virtuals?: boolean | string[]

apply virtual getters (can override getters option)