Skip to content

"Class constructor ObjectId cannot be invoked without 'new'" - on upgrading from 6x to 7x - not in upgrade notes #14020

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

Closed
2 tasks done
eliezra236 opened this issue Oct 31, 2023 · 0 comments
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@eliezra236
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

I am upgrading from 6x to 7x and started to get this issue
Class constructor ObjectId cannot be invoked without 'new'

Running the same code on mongoose@6.7.2 works and on mongoose@7.0.0 or mongoose@7.6.4 (latest as the day of this issue) it throws this new error:

const {Types: {ObjectId}} = require('mongoose');

const obj = ObjectId('5e9b9b5b9c6f2b0b4c9b3b3b');

console.log(obj);

This change is not mentioned on the migration guide:
https://mongoosejs.com/docs/migrating_to_7.html

@vkarpov15 vkarpov15 added this to the 7.6.5 milestone Oct 31, 2023
vkarpov15 added a commit that referenced this issue Oct 31, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
penguinpee Sandro
Fix #14020
vkarpov15 added a commit that referenced this issue Oct 31, 2023
docs(migrating_to_7): add note about requiring `new` with `ObjectId`
@IslandRhythms IslandRhythms added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests

3 participants