Skip to content

Conversation

@LijieZhang1998
Copy link
Contributor

No description provided.


NumberLong.prototype.nativeToString = NumberLong.prototype.toString;
NumberLong.prototype.toString = function () {
return `NumberLong(${this.nativeToString()})`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't catch all cases correctly – if the number is larger than 2**31-1 in magnitude, then the legacy server added quotes around the value

(mongosh intentionally always adds quotes, and I'd consider going that route here too, even if it limits compatibility with the legacy server shell/$function)

Comment on lines 402 to 407
const str = this.nativeToString();
const bigIntValue = BigInt(str);
const unsigned64 = bigIntValue < 0n
? bigIntValue + (1n << 64n)
: bigIntValue;
return Number((unsigned64 >> 32n) & 0xFFFFFFFFn);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const str = this.nativeToString();
const bigIntValue = BigInt(str);
const unsigned64 = bigIntValue < 0n
? bigIntValue + (1n << 64n)
: bigIntValue;
return Number((unsigned64 >> 32n) & 0xFFFFFFFFn);
return this.high;

Comment on lines 415 to 420
const str = this.nativeToString();
const bigIntValue = BigInt(str);
const unsigned64 = bigIntValue < 0n
? bigIntValue + (1n << 64n)
: bigIntValue;
return Number(unsigned64 & 0xFFFFFFFFn);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const str = this.nativeToString();
const bigIntValue = BigInt(str);
const unsigned64 = bigIntValue < 0n
? bigIntValue + (1n << 64n)
: bigIntValue;
return Number(unsigned64 & 0xFFFFFFFFn);
return this.low;

(you'll want to also verify that these have the correct signedness for negative values)

@addaleax addaleax merged commit 4ae06cf into mongodb-labs:main Oct 13, 2025
2 checks passed
@addaleax
Copy link
Collaborator

Published in @mongosh/[email protected] 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants