-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
BigInt/Int64 negative value parse error #15200
Comments
Simpler repro diff --git a/test/bigint.test.js b/test/bigint.test.js
index e3d00418e..14e3bddac 100644
--- a/test/bigint.test.js
+++ b/test/bigint.test.js
@@ -88,7 +88,7 @@ describe('BigInt', function() {
let Test;
before(async function() {
- db = await start();
+ db = await start({useBigInt64: true});
const schema = new Schema({
myBigInt: BigInt
@@ -114,14 +114,14 @@ describe('BigInt', function() {
});
it('becomes a bigint with lean using useBigInt64', async function() {
- await Test.create({ myBigInt: 7n });
+ await Test.create({ myBigInt: 18446744073709551613n });
const doc = await Test.
- findOne({ myBigInt: 7n }).
+ findOne({ myBigInt: 18446744073709551613n }).
setOptions({ useBigInt64: true }).
lean();
assert.ok(doc);
- assert.strictEqual(doc.myBigInt, 7n);
+ assert.strictEqual(doc.myBigInt, -3n);
});
it('can query with comparison operators', async function() { This test fails on current version - but I think its not due to code changes in mongoose |
this will pass the test mentioned above diff --git a/package.json b/package.json
index 663a81830..990478ec3 100644
--- a/package.json
+++ b/package.json
@@ -19,9 +19,9 @@
],
"license": "MIT",
"dependencies": {
- "bson": "^6.10.1",
+ "bson": "5.5.0",
"kareem": "2.6.3",
- "mongodb": "~6.12.0",
+ "mongodb": "5.7.0",
"mpath": "0.9.0",
"mquery": "5.0.0",
"ms": "2.1.3", |
This issue seems to be indicative of not setting 'use strict';
const mongoose = require('mongoose');
mongoose.set('debug', true);
(async function() {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_test', { useBigInt64: true });
const schema = new mongoose.Schema({
myBigInt: BigInt
});
const Test = mongoose.model('Test', schema);
await Test.deleteMany({});
const { _id } = await Test.create({ myBigInt: 18446744073709551613n });
const doc = await Test.findById(_id);
doc.markModified('myBigInt');
await doc.save();
console.log(await Test.findById(_id));
})(); This does bring up a good point that |
…unds of what MongoDB can safely store Fix #15200
fix(bigint): throw error when casting BigInt that's outside of the bounds of what MongoDB can safely store
Prerequisites
Mongoose version
8.9.5
Node.js version
22
MongoDB server version
8.0.4
Typescript version (if applicable)
No response
Description
BigInt field with negative value parse error in latest mongoose(8.9.5), bug works well in 7.8.4.
Steps to Reproduce
Model
Expected Behavior
The text was updated successfully, but these errors were encountered: