-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
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
Using typeKey
and required
throws a TypeError: Invalid schema configuration
#14950
Comments
I'm unable to repro, the following script runs successfully: import mongoose from 'mongoose';
const { Schema } = mongoose;
const SightingSchema = new Schema(
{
_id: { $type: Schema.Types.ObjectId, required: true },
location: {
type: { $type: String, required: true },
coordinates: [{ $type: Number }],
},
},
{
typeKey: "$type",
}
); Are you sure you don't have somewhere in your schema where you're using const SightingSchema = new Schema(
{
_id: { $type: Schema.Types.ObjectId, required: true },
location: {
type: { $type: String, required: true },
coordinates: [{ $type: Number }],
},
test: { type: String, required: true }
},
{
typeKey: "$type",
}
); We're investigating a workaround for the |
…type: { type: String }` Fix #14950
types: correct schema type inference when using nested typeKey like `type: { type: String }`
Prerequisites
Mongoose version
8.6.3
Node.js version
20.x
MongoDB server version
6.0.16
Typescript version (if applicable)
5.5.1
Description
When defining a model like:
I get the error:
When I don't use the
typeKey: $type
and just usetype
it works but can't be right for GeoJSON and as recommended in the Mongoose docs - https://mongoosejs.com/docs/guide.html#typeKey) and I get a warning in my tests:Steps to Reproduce
typeKey: $type
in the optionsrequired: true
for the fieldExpected Behavior
I expect it work just as it does without using a custom
typeKey
.The text was updated successfully, but these errors were encountered: