-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Closed
Copy link
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
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:
const SightingSchema = new Schema(
{
_id: { $type: Schema.Types.ObjectId, required: true },
...,
location: {
type: { $type: String, required: true },
coordinates: [{ $type: Number }],
},
},
{
typeKey: "$type",
}
);
I get the error:
TypeError: Invalid schema configuration: `true` is not a valid type at path `required`. See https://bit.ly/mongoose-schematypes for a list of valid schema types.
3 |
> 4 | const SightingSchema = new Schema(
| ^
5 | {
6 | _id: { $type: Schema.Types.ObjectId, required: true }
at Schema.add (node_modules/mongoose/lib/schema.js:740:13)
at Schema.add (node_modules/mongoose/lib/schema.js:778:12)
at new Schema (node_modules/mongoose/lib/schema.js:143:10)
...
When I don't use the typeKey: $type and just use type 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:
Property 'coordinates' does not exist on type '{ type?: string | null | undefined; required?: unknown; }'
Steps to Reproduce
- use
typeKey: $typein the options - use
required: truefor the field
Expected Behavior
I expect it work just as it does without using a custom typeKey.
Metadata
Metadata
Assignees
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request