From f88eb2524b65a68ff893c90a03c04f0913c1913e Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sun, 12 Jul 2020 13:53:04 -0400 Subject: [PATCH] fix(query): delete top-level `_bsontype` property in queries to prevent silent empty queries Backport fix for #8222 Fix #8241 --- lib/cast.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/cast.js b/lib/cast.js index 7f475edfeb4..339c031f14d 100644 --- a/lib/cast.js +++ b/lib/cast.js @@ -23,6 +23,12 @@ module.exports = function cast(schema, obj, options, context) { throw new Error('Query filter must be an object, got an array ', util.inspect(obj)); } + // 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')) { + delete obj._bsontype; + } + var paths = Object.keys(obj); var i = paths.length; var _keys;