aggregate $match Error: Type 'ObjectId' is not assignable to type 'Expression'.
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.4.0
Node.js version
16.14.0
MongoDB server version
5.0.9
Description
update to latest version and get error on aggregate
await Model.aggregate([
{
$match: { _id: new mongoose.Types.ObjectId('stringObjecId') },
},
]);
get Error Type 'ObjectId' is not assignable to type 'Expression'.
how to solve this?
Steps to Reproduce
await Model.aggregate([
{
$match: { _id: new mongoose.Types.ObjectId('stringObjecId') },
},
]);
Expected Behavior
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Type 'ObjectId' is not assignable to type 'Expression' in ...
guys when i want to aggregate in mongoDB using typescript i got this error. Type 'ObjectId' is not assignable to type 'Expression'.
Read more >Aggregation pipeline typing broke after update cannot match ...
Type 'ObjectId' is not assignable to type 'Expression'. If I remove the cast, it does not work, but typing error goes away.
Read more >Type 'ObjectId' is not assignable to type 'never' - MongoDB
When i use non-array functions like $find etc. it works fine. Do i have to type every Collection? How would it work with...
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 >MongoDB Typescript Error "Type 'ObjectId' is not assignable to ...
Coding example for the question MongoDB Typescript Error "Type 'ObjectId' is not assignable to type 'never'-mongodb.
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 FreeTop 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
Top GitHub Comments
Found more things that are being broken by the types. All 3 of these here:
Errors:
@jyeros this should be fixed in 6.4.3 with https://github.com/Automattic/mongoose/commit/9f3f8ebb951a37cdb43934c38e6501782e35fa2f .