Skip to content

Commit a6b4edb

Browse files
committed
Check if 'str' property already exist
Property should not be defined if already existing
1 parent 2dbdab5 commit a6b4edb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

snippets/mongocompat/mongotypes.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,14 @@ ObjectId.prototype.tojson = function() {
414414
return this.toString();
415415
};
416416

417-
Object.defineProperty(ObjectId.prototype, 'str', {
418-
enumerable: true,
419-
get() {
420-
return this.toHexString();
421-
}
422-
});
417+
if (!ObjectId.prototype.hasOwnProperty('str')) {
418+
Object.defineProperty(ObjectId.prototype, 'str', {
419+
enumerable: true,
420+
get() {
421+
return this.toHexString();
422+
}
423+
});
424+
}
423425

424426
ObjectId.prototype.valueOf = function() {
425427
return this.str;

0 commit comments

Comments
 (0)