Skip to content

[interop] Array default with transfrom #8012

Closed
@hasezoey

Description

@hasezoey

mongoose version: 5.6.6(NPM)
nodejs: 12.7.0

reproduce script:

import * as mongoose from "mongoose";

const testSchema = new mongoose.Schema({
    testArray: [{ default: ["testDefault"], type: String, lowercase: true }]
});

const testModel = mongoose.model("test", testSchema);

(async () => {
    mongoose.set("debug", true);
    await mongoose.connect(`mongodb://mongodb:27017/`, {
        useNewUrlParser: true,
        useFindAndModify: true,
        useCreateIndex: true,
        dbName: "verify",
        user: "user",
        pass: "passwd",
        authSource: "admin",
        autoIndex: true
    });

    const doc = new testModel({});
    await doc.save();
    console.log(doc.toObject());

    await mongoose.disconnect();
})();

log

Mongoose: tests.insertOne({ testArray: [], _id: ObjectId("5d38883c65478f080346dfad"), __v: 0 }, { session: null })
{ testArray: [], _id: 5d38883c65478f080346dfad, __v: 0 }

current behavior: dosnt apply the default value when formatted so / has a "string" transform
wanted behavior: applys default value when formatted so

PS: i make this a question, because i dont know if this is an actual bug
and if there is actually an other issue having this problem, i didnt find it...

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis issue is due to a mistake or omission in the mongoosejs.com documentation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions