We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the current behavior?
If I create a schema containing a Map of another schema, the type casting and validation does not seem to be working correctly.
Map
If the current behavior is a bug, please provide the steps to reproduce.
const userSchema = new mongoose.Schema({ modules: { type: Map, of: { isRequired: { type: String, required: true }, hasDefault: { type: String, default: "test" } } } }) const User = model('User', userSchema) // Successfully creates user User.create({ modules: { example: { /* missing isRequired and hasDefault property */ } } })
What is the expected behavior?
Throw an error as a result of missing isRequired and fill in hasDefault to be "test".
isRequired
hasDefault
"test"
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 12.3.1 Mongoose: 5.5.12 MongoDB: Atlas
The text was updated successfully, but these errors were encountered:
The solution is to nest schemas:
const userSchema = new mongoose.Schema({ modules: { type: Map, of: { new mongoose.Schema({ isRequired: { type: String, required: true }, hasDefault: { type: String, default: "test" } }) } } })
Sorry, something went wrong.
@vkarpov15 In Mongoose Map schema, of should be one of the valid value of type.
of
type
Like in normal schema, type: { xxx: x } is actually interpreted as Mixed type so it makes sense that of: { xxx: x } is interpreted as Mixed type too.
type: { xxx: x }
Mixed
of: { xxx: x }
If we really want to support this, I think #7181 will cover this issue and need to be discussed.
test(map): repro #7859
d03129c
eb5078e
No branches or pull requests
What is the current behavior?
If I create a schema containing a
Map
of another schema, the type casting and validation does not seem to be working correctly.If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Throw an error as a result of missing
isRequired
and fill inhasDefault
to be"test"
.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 12.3.1
Mongoose: 5.5.12
MongoDB: Atlas
The text was updated successfully, but these errors were encountered: