From b03faf5ceec529c13b17684b8bf250b2b451b060 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 23 Oct 2019 10:21:37 -0400 Subject: [PATCH] fix(query): allow findOne(objectid) and find(objectid) Fix #8268 --- lib/cast.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/cast.js b/lib/cast.js index 3dfd651acd2..94bdb1d2b9e 100644 --- a/lib/cast.js +++ b/lib/cast.js @@ -28,8 +28,10 @@ module.exports = function cast(schema, obj, options, context) { } // bson 1.x has the unfortunate tendency to remove filters that have a top-level - // `_bsontype` property. Should remove this when we upgrade to bson 4.x. See gh-8222 - if (obj.hasOwnProperty('_bsontype')) { + // `_bsontype` property. But we should still allow ObjectIds because + // `Collection#find()` has a special case to support `find(objectid)`. + // Should remove this when we upgrade to bson 4.x. See gh-8222, gh-8268 + if (obj.hasOwnProperty('_bsontype') && obj._bsontype !== 'ObjectID') { delete obj._bsontype; }