You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug? bug
What is the current behavior?
checking equality of two ObjectIds with the same ID is always false.
When I run myObjectId.valueOf() it appears to output a new ObjectId instead of the string representation like expected.
If the current behavior is a bug, please provide the steps to reproduce.
var mongoose = require('mongoose');
var ObjectId = mongoose.Types.ObjectId;
var a = new ObjectId('6143b55ac9a762738b15d4f0');
var b = new ObjectId('6143b55ac9a762738b15d4f0');
console.log(a == b); // false
console.log(a.valueOf() == b.valueOf()); // false
I believe the issue is due to this check:
if (ObjectId.prototype.valueOf === void 0) {
ObjectId.prototype.valueOf = function objectIdValueOf() {
return this.toString();
};
}
When I run the ObjectId.prototype.valueOf === void 0 on the mongodb driver ObjectId it's false, so I believe the overridden function isn't being applied.
What is the expected behavior?
According to the 6.0 Migration document:
ObjectId valueOf()
Mongoose now adds a valueOf() function to ObjectIds. This means you can now use == to compare two ObjectId instances.
Although this doesn't seem to be the case.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 12.16
Mongoose: 6.0.6
MongoDb: 4.4
The text was updated successfully, but these errors were encountered:
Re: valueOf() returning an object, that's a bug and we'll fix it for v6.0.8.
Re: the claim that "you can now use == to compare two ObjectId instances", that's unfortunately also wrong. Two objects cannot be == each other without being the same reference. Equality in JavaScript is pretty strict about that. But what you should be able to do now is compare an object id against a string:
It seems mongodb's ObjectId already supports this, and it also has an .equals method for comparing two ids, so it seems overriding valueOf is not necessary.
Do you want to request a feature or report a bug?
bug
What is the current behavior?
checking equality of two
ObjectId
s with the same ID is always false.When I run
myObjectId.valueOf()
it appears to output a newObjectId
instead of the string representation like expected.If the current behavior is a bug, please provide the steps to reproduce.
I believe the issue is due to this check:
When I run the
ObjectId.prototype.valueOf === void 0
on the mongodb driverObjectId
it's false, so I believe the overridden function isn't being applied.What is the expected behavior?
According to the 6.0 Migration document:
Although this doesn't seem to be the case.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 12.16
Mongoose: 6.0.6
MongoDb: 4.4
The text was updated successfully, but these errors were encountered: