diff --git a/lib/schema/bigint.js b/lib/schema/bigint.js index 6baec1f7ef..4dcebcbd41 100644 --- a/lib/schema/bigint.js +++ b/lib/schema/bigint.js @@ -209,7 +209,7 @@ SchemaBigInt.prototype.castForQuery = function($conditional, val, context) { return handler.call(this, val); } - return this.applySetters(null, val, context); + return this.applySetters(val, context); } try { diff --git a/lib/schema/boolean.js b/lib/schema/boolean.js index a887a9e07e..1cbade08c6 100644 --- a/lib/schema/boolean.js +++ b/lib/schema/boolean.js @@ -253,7 +253,7 @@ SchemaBoolean.prototype.castForQuery = function($conditional, val, context) { return handler.call(this, val); } - return this.applySetters(null, val, context); + return this.applySetters(val, context); } try { diff --git a/lib/schema/int32.js b/lib/schema/int32.js index 51594934e9..6838d22f2b 100644 --- a/lib/schema/int32.js +++ b/lib/schema/int32.js @@ -7,6 +7,7 @@ const CastError = require('../error/cast'); const SchemaType = require('../schemaType'); const castInt32 = require('../cast/int32'); +const handleBitwiseOperator = require('./operators/bitwise'); /** * Int32 SchemaType constructor. @@ -200,7 +201,11 @@ SchemaInt32.$conditionalHandlers = { $gt: handleSingle, $gte: handleSingle, $lt: handleSingle, - $lte: handleSingle + $lte: handleSingle, + $bitsAllClear: handleBitwiseOperator, + $bitsAnyClear: handleBitwiseOperator, + $bitsAllSet: handleBitwiseOperator, + $bitsAnySet: handleBitwiseOperator }; /*! @@ -228,7 +233,7 @@ SchemaInt32.prototype.castForQuery = function($conditional, val, context) { return handler.call(this, val); } - return this.applySetters(null, val, context); + return this.applySetters(val, context); } try { diff --git a/test/cast.test.js b/test/cast.test.js index 9ee9fbca1a..2be2186aae 100644 --- a/test/cast.test.js +++ b/test/cast.test.js @@ -123,6 +123,12 @@ describe('cast: ', function() { { x: { $bitsAnyClear: Buffer.from([3]) } }); }); + it('with int32 (gh-15170)', function() { + const schema = new Schema({ x: 'Int32' }); + assert.deepEqual(cast(schema, { x: { $bitsAnySet: 3 } }), + { x: { $bitsAnySet: 3 } }); + }); + it('throws when invalid', function() { const schema = new Schema({ x: Number }); assert.throws(function() { @@ -250,4 +256,10 @@ describe('cast: ', function() { 'state.fieldFoo': '44' }); }); + + it('treats unknown operators as passthrough (gh-15170)', function() { + const schema = new Schema({ x: Boolean }); + assert.deepEqual(cast(schema, { x: { $someConditional: true } }), + { x: { $someConditional: true } }); + }); });