Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwise query on Int32 field throws server error #15170

Closed
2 tasks done
KeyboardRage opened this issue Jan 8, 2025 · 0 comments · Fixed by #15176
Closed
2 tasks done

Bitwise query on Int32 field throws server error #15170

KeyboardRage opened this issue Jan 8, 2025 · 0 comments · Fixed by #15176
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@KeyboardRage
Copy link

KeyboardRage commented Jan 8, 2025

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.9.3

Node.js version

22.11.0

MongoDB server version

7.0.15

Typescript version (if applicable)

5.7.2

Description

I previously used a plugin to support Int32 in schemas. With the latest version of Mongoose I could drop this plugin.
However, the queries that used to work now no longer works.

It seems to turn the query value from a number into null.
The database then throws an error for invalid querying.

The error it throws:

MongoServerError: myField takes an Array, a number, or a BinData but received: $bitsAnySet: null

Steps to Reproduce

I can reproduce it with this setup.

const mongoose = require("mongoose");
mongoose.connect("mongodb://127.0.0.1:27017/test");

const Config = mongoose.model("Config", {
	"myField": {
		type: mongoose.SchemaTypes.Int32,
		required: true,
	},
});

const config = new Config({ myField: 3 });
config
	.save()
	.then(() => {
		return Config.findOne({ myField: {$bitsAnySet: 1} });
	})
	.then(console.log);

Expected Behavior

The DB will find the record and return it.

@KeyboardRage KeyboardRage changed the title Bit values in a $bit query to Int32 type fields does not work Bitwise query on Int32 field throws server error Jan 9, 2025
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Jan 9, 2025
@vkarpov15 vkarpov15 added this to the 8.9.5 milestone Jan 11, 2025
vkarpov15 added a commit that referenced this issue Jan 13, 2025
fix(schema): handle bitwise operators on Int32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants