-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Monkey patching of ObjectId, but still undefined? #14154
Comments
|
Hey, thanks for your quick answer... I tried to run this then, and it passes:
|
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days |
Up :) I add some clarification, but I don't know if/how I can remove the label @vkarpov15 |
Please modify the script to demonstrate your issue. const mongoose = require('mongoose');
const { ObjectId } = require('mongodb');
let MongoDBObjectID = ObjectId;
const mongodbId = new MongoDBObjectID('5b348a71fe5e561dd1c70628');
console.log('what is mongodbId', mongodbId);
const mongooseObjectId = new mongoose.Types.ObjectId('5b348a71fe5e561dd1c70628');
console.log('what is mongoose object id', mongooseObjectId);
console.log(mongooseObjectId._id); |
I modified @IslandRhythms ' script slightly, but still not able to repro this issue: const mongoose = require('mongoose');
const { ObjectId } = require('mongodb');
let MongoDBObjectID = ObjectId;
const mongodbId = new MongoDBObjectID('5b348a71fe5e561dd1c70628');
console.log('what is mongodbId', mongodbId._id);
const mongooseObjectId = new mongoose.Types.ObjectId('5b348a71fe5e561dd1c70628');
console.log('what is mongoose ObjectId', mongooseObjectId._id); Output:
@nicolas-urbantz can you please run |
Thanks, I'll have a look tomorrow 🫶 |
@vkarpov15 , you are right I think, we have another version. I copy/paste your script and here is my output:
Output of
I see that mongoose is using |
@nicolas-urbantz yes I'd recommend you use |
Make sense! Thank you for your time 🙏 |
Prerequisites
Mongoose version
7.6.4
Node.js version
20
MongoDB server version
5.9.1
Typescript version (if applicable)
5.1.6
Description
Hello!
We are upgrading an old codebase from mongoose 5 to 7. I see that mongoose is monkey patching the "native"
ObjectId
by adding a_id
attribute... But I'm wondering if the type is correct because in the code, I can see:while, in reality, it's undefined (see steps to reproduce).
I saw that issue, but it doesn't answer my question :/
Steps to Reproduce
This is my unit test:
Expected Behavior
It passes, but shouldn't it fail? Or shouldn't the monkey patch say that
_id
could be undefined?The text was updated successfully, but these errors were encountered: