This commit is contained in:
2020-08-20 11:44:32 +02:00
parent 4715fc1814
commit 6aceefeb2f
2891 changed files with 11239 additions and 347539 deletions

View File

@@ -66,7 +66,7 @@ var ObjectID = function ObjectID(id) {
} else if (id != null && id.length === 12) {
// assume 12 byte string
this.id = id;
} else if (id != null && id.toHexString) {
} else if (id != null && typeof id.toHexString === 'function') {
// Duck-typing to support ObjectId from different npm packages
return id;
} else {
@@ -357,7 +357,10 @@ ObjectID.isValid = function isValid(id) {
}
// Duck-Typing detection of ObjectId like objects
if (id.toHexString) {
if (
typeof id.toHexString === 'function' &&
(id.id instanceof _Buffer || typeof id.id === 'string')
) {
return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id));
}