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

TypeError: this.$__setSchema is not a function #14281

Closed
2 tasks done
adamreisnz opened this issue Jan 22, 2024 · 4 comments · Fixed by #14288
Closed
2 tasks done

TypeError: this.$__setSchema is not a function #14281

adamreisnz opened this issue Jan 22, 2024 · 4 comments · Fixed by #14288
Labels
priority Automatically set for Mongoose Pro subscribers
Milestone

Comments

@adamreisnz
Copy link
Contributor

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.0.2

Node.js version

21.6

MongoDB server version

7.0

Typescript version (if applicable)

n/a

Description

Our error reporting tool captured the following error, which originated from Mongoose and seems to be an internal Mongoose error where the __setSchema function appears to be missing:

Steps to Reproduce

TypeError: this.$__setSchema is not a function
node_modules/mongoose/lib/document.js in Mongoose.Document at line 91:10

  options = Object.assign({}, options);
  // Support `browserDocument.js` syntax
  if (this.$__schema == null) {
    const _schema = utils.isObject(fields) && !fields.instanceOfSchema ?
      new Schema(fields) :
      fields;
    this.$__setSchema(_schema);
    fields = skipId;
    skipId = options;
    options = arguments[4] || {};
  }
  this.$__ = new InternalCache();
node_modules/mongoose/lib/model.js in Mongoose.Model at line 125:12

Don't have exact schema's or an isolated reproducible case at this stage, but if the method has truly been removed or renamed it should be easy to track down.

Expected Behavior

No error to be thrown

@mongoose-pro-bot mongoose-pro-bot added the priority Automatically set for Mongoose Pro subscribers label Jan 22, 2024
@vkarpov15
Copy link
Collaborator

The $__setSchema method has not been removed or renamed. The only thing that looks strange from this stack trace is that it looks like you're hitting the "browser document" code path, which is definitely unexpected. Do you have a more complete stack trace?

@adamreisnz
Copy link
Contributor Author

Hmm, I talked to our developer and he said the only thing he changed was that he was using mongoose.Model('System') instead of mongoose.model('System'), which worked on his local environment apparently but triggered the above error in production.

The issue that caused it is thus resolved, so perhaps it is not worth the time to investigate further, if the method is still there.

@vkarpov15 vkarpov15 added this to the 8.1.1 milestone Jan 23, 2024
vkarpov15 added a commit that referenced this issue Jan 24, 2024
vkarpov15 added a commit that referenced this issue Jan 24, 2024
fix(model): throw readable error when calling `Model()` with a string instead of `model()`
@vkarpov15
Copy link
Collaborator

@adamreisnz this is more of an error message issue than a bug, calling mongoose.Model('foo') instead of mongoose.model('foo') is an error. We improved that error message in v8.1.1 to be a bit more clear.

@adamreisnz
Copy link
Contributor Author

Cheers thanks for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority Automatically set for Mongoose Pro subscribers
Projects
None yet
3 participants