Skip to content
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

Invalid schema configuration: True is not a valid type at path createdAt.immutable #10761

Closed
nicecatch opened this issue Sep 22, 2021 · 1 comment
Assignees
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@nicecatch
Copy link

nicecatch commented Sep 22, 2021

I updated to Mongoose 6.0.7 and all of my models use timestamps: true

Here an example:

export interface IDocumentProjectRequest extends IProjectRequest, Document {}

const projectRequestSchema = new Schema(
  {
    user: { type: Schema.Types.ObjectId, ref: "users", required: true },
    diagnostic: {
      type: Schema.Types.ObjectId,
      ref: "diagnostic",
      required: true,
    },
    project: { type: Schema.Types.ObjectId, ref: "project" },
  },
  { collection: "projectRequests", timestamps: true }
);

export const ProjectRequest = mongoose.model<IDocumentProjectRequest>(
  "projectRequest",
  projectRequestSchema
);

but when I try to run the project I get this error

TypeError: Invalid schema configuration: `True` is not a valid type at path `createdAt.immutable`. See http://bit.ly/mongoose-schematypes for a list of valid schema types.
    at Schema.interpretAsType (C:\src\server\node_modules\mongoose\lib\schema.js:1019:11)
    at Schema.path (C:\src\server\node_modules\mongoose\lib\schema.js:677:27)
    at Schema.add (C:\src\server\node_modules\mongoose\lib\schema.js:495:12)
    at Schema.add (C:\src\server\node_modules\mongoose\lib\schema.js:506:12)
    at setupTimestamps (C:\src\server\node_modules\mongoose\lib\helpers\timestamps\setupTimestamps.js:36:10)
    at Schema.setupTimestamp (C:\src\server\node_modules\mongoose\lib\schema.js:1221:10)
    at new Schema (C:\src\server\node_modules\mongoose\lib\schema.js:141:8)
    at Object.<anonymous> (C:\src\serverr\src\db\models\Account.ts:7:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module._compile (C:\src\server\node_modules\source-map-support\source-map-support.js:568:25)
[ERROR] 09:09:08 TypeError: Invalid schema configuration: `True` is not a valid type at path `createdAt.immutable`. See http://bit.ly/mongoose-schematypes for a list of valid schema types.

this seems to be linked to this pull request #10267
because when I manually revert
schemaAdditions[createdAt] = { type: Date, immutable: true };
to
schemaAdditions[createdAt] = Date;
it works again

@nicecatch
Copy link
Author

nicecatch commented Sep 22, 2021

Found the problem

We have a model with a custom typeKey option (since one of the fields name is 'type')
The timestamps plugin doesn't respect this parameter and leads to that error
For now we have renamed the 'type' field in the model to a different name

@vkarpov15 vkarpov15 added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary and removed seen labels Sep 24, 2021
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Sep 25, 2021
@vkarpov15 vkarpov15 added this to the 6.0.8 milestone Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants