We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 29aa89c commit 4b800aeCopy full SHA for 4b800ae
lib/objectid.js
@@ -85,7 +85,7 @@ class ObjectId {
85
} else if (id != null && id.length === 12) {
86
// assume 12 byte string
87
this.id = id;
88
- } else if (id != null && id.toHexString) {
+ } else if (id != null && typeof id.toHexString === 'function') {
89
// Duck-typing to support ObjectId from different npm packages
90
return ObjectId.createFromHexString(id.toHexString());
91
} else {
@@ -338,7 +338,10 @@ class ObjectId {
338
}
339
340
// Duck-Typing detection of ObjectId like objects
341
- if (id.toHexString) {
+ if (
342
+ typeof id.toHexString === 'function' &&
343
+ (id.id instanceof _Buffer || typeof id.id === 'string')
344
+ ) {
345
return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id));
346
347
0 commit comments