Bug: mongoose.Types.ObjectId doesn't extend mongodb.ObjectId properly (TypeScript)
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
user: mongoose.Types.ObjectId;
user._id._id._id._id._id._id //...
user._id.toHexString() // error: toHexString() doesn't exist on _id
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Version 2.6.10 changed ObjectId
and Schema.index()
behavior.
// before (worked)
MySchema.index({ key: 1, star: 1 }, { unique: true });
// today (not sure if it works)
MySchema.index({ key: 1, star: 1 }, { weights: { unique: true } });
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.
Mongoose: 6.2.10
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Mongoose TypeScript ObjectId casting - Type 'string' is not ...
When I try to cast string[] to Schema.Types.ObjectId[] array, the error goes away but this cannot be the solution, since it crashes at...
Read more >Mongoose findById method not properly casting to id strings to ...
The tutorial recommends that we use mongoose.Types.ObjectId() to convert the id to a type that can be used. I implemented the mongoose.
Read more >Mongoose v6.8.2: API docs
Used for declaring paths in your schema that should be MongoDB ObjectIds. Do not use this to create a new ObjectId instance, use...
Read more >Strongly typed models with Mongoose and TypeScript
To do this in Mongoose you pass the type as mongoose.Schema.Types.ObjectId, having @types/mongoose installed gives your application access ...
Read more >mongoose/index.d.ts - UNPKG
38, // eslint-disable-next-line @typescript-eslint/ban-types ... 51, * Do not use this to create a new ObjectId instance, use `mongoose.Types.ObjectId`.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have occasionally seen typescript do things like that, where things fail but then later (after some kind of cache expires?) it works. glad that was an easy fix 😉
the _id recursion thing is from what I can tell expected.
I temporarily rolled back to version 6.2.9 which everything works fine