-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 get's returned as undefined but is shown in mongoDB Atlast as Int64 #13791
Comments
@vkarpov15 when 7.5.1 will be releases? facing same issue, i see fixed being merged but that fix is not working locally for me |
I tried it also with 7.5.0, but it does not work. |
@vkarpov15 I did make a fix for myself. but I don't feel 100% comfortable that is production-ready. the file lib/cast/bigint.js or with more checks for long param the main issue is how check that it is a new Long("123") |
The initial findOne call does not have the reward field
const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
n: Number,
reward: BigInt
});
const Test = mongoose.model('Test', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
let a = await Test.create({n: 1, reward: 14055648105137340n});
let b = await Test.findOne({n: 1});
console.log(14055648105137340n);
console.log('create : ', a);
console.log('findOne : ', b);
let c = await Test.create({n: 2, reward: 1305564810513734n});
let d = await Test.findOne({n: 2});
console.log(1305564810513734n);
console.log('create : ', c);
console.log('findOne : ', d);
} |
fix(document): handle MongoDB Long when casting BigInts
Prerequisites
Mongoose version
6.4.5
Node.js version
16.20.1
MongoDB server version
7.0.0
Typescript version (if applicable)
5.2.2
Description
The value 14055648105137340n returns undefined if you save it in a BigInt
MongoDB Atlas shows it nicely as an Int64.
The signed type, Int64, can hold values from -9223372036854775808 to 9223372036854775807. The unsigned type, Uint64, can hold values from 0 to 18446744073709551615.
9223372036854775807 <- max range
14055648105137340n <- The value we tried to use doesn't work
1305564810513734n <- This value does work
I added a fix (#13787) with patch package to test if this helps but it didn't help
Steps to Reproduce
Expected Behavior
We expected to get the BigInt up to 9223372036854775807n returned
The text was updated successfully, but these errors were encountered: