Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion snippets/mongocompat/mongotypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,14 @@ if (typeof NumberDecimal !== 'undefined') {
if (!NumberDecimal.prototype) {
NumberDecimal.prototype = {};
}
NumberDecimal.prototype.nativeToString = NumberDecimal.prototype.toString

NumberDecimal.prototype.tojson = function() {
return this.toString();
return this.nativeToString();
};

NumberDecimal.prototype.toString = function() {
return `NumberDecimal("${this.nativeToString()}")`;
};
}

Expand Down
3 changes: 3 additions & 0 deletions snippets/mongocompat/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ assert.strictEqual(minLong.bottom, 0);
assert.strictEqual(minLong.exactValueString, "-9223372036854775808");
const nl2 = NumberLong("200");
assert.strictEqual(maxLong.compare(nl2), 1);
const decimal = NumberDecimal("1.1");
assert.strictEqual(decimal.toString(), 'NumberDecimal("1.1")');
assert.strictEqual(decimal.tojson(), '1.1');
Copy link
Collaborator

Choose a reason for hiding this comment

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

root@bce3f00f5209:/# mongo --nodb
MongoDB shell version v5.0.31
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
> NumberDecimal('1.1').tojson()
NumberDecimal("1.1")

seems to disagree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct, sorry I was focused on maintaining the previous output, not compatibility. Will update