Unable to use mongo _id for await User.find(_id).
See original GitHub issueAble to find user with _id (objectID2) and user generated _id (abc2) but not working with auto-generated _id (“607cf59ec294c8c3f1261e4f”)
await User.find(_id as any) // works with _id as objectId
User {
_id: ObjectId2 {
[Symbol(id)]: Buffer2(12) [
96, 124, 245, 158, 194,
148, 200, 195, 241, 38,
30, 79
]
},
name: "user1"
}
await User.find("607cf59ec294c8c3f1261e4f") // undefined
await User.find("abc1") // works
Auto-generated _id is 607cf59ec294c8c3f1261e4f
Auto-generated _id returns undefined
User generated _id works
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Can't get _id mongodb - node.js - Stack Overflow
findById is not taking an object, you just need to pass the id directly to findById const course = await Course.findById(id).lean().
Read more >Mongoose v6.8.1: API docs
The Mongoose ObjectId SchemaType. Used for declaring paths in your schema that should be MongoDB ObjectIds. Do not use this to create a...
Read more >Can't update document with object from Stripe - MongoDB
I've been updating the stripe checkout and know need to append the object to the user document each time there's a purchase. I've...
Read more >Mongoose findById method not properly casting to id strings to ...
Running db.users.findOne({ _id: "<id-string>" }) in the mongo shell returns the proper user document. Using the findOne ...
Read more >mongodb cast to objectid failed for value - You.com - You.com
One way to resolve this is to add a check prior to your findById call to see if id is a valid 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 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
Tried this in #240
Sure. I’ll try it.