[SERVER-14217] Support NumberLong arithmetic in mongo shell and server JS Created: 10/Jun/14  Updated: 10/May/22

Status: Backlog
Project: Core Server
Component/s: JavaScript, Shell
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Kevin Pulo Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Unresolved Votes: 3
Labels: move-sa, platforms-re-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-14846 Expose basic arithmetic operations fo... Closed
Related
related to SERVER-4141 NumberLong.bottom does not return val... Closed
related to SERVER-19943 Support NumberDecimal arithmetic in m... Closed
is related to SERVER-19676 NumberDecimal(...) + NumberDecimal(..... Closed
Participants:

 Description   

Currently, NumberLongs are automatically cast to numbers when arithmetic is performed on them (courtesy of .toNumber()). This means that doing something like trying to subtract two NumberLongs returns a double-precision number, not a NumberLong. This causes a loss of precision, and this in turn means that hashed shard key values can't be manipulated in the shell.

Supporting natural syntax like NumberLong("...") - NumberLong("...") isn't necessary, it would suffice to be able to do something like NumberLong("...").subtract(NumberLong("...")) and get back a NumberLong.



 Comments   
Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Comment by Matt Kangas [ 11/Aug/14 ]

As of r2.7.4, potential contributors should start reading here:

Comment by Vincent [ 11/Aug/14 ]

Adding a "BigNumber" library is not a good option for map-reduce operations, because it requires you to embed the library in the map or reduce methods, so it's run at every single map or reduce call, causing a big overhead.
Beside this, those operators are probably already somewhere in MongoDB (as update use them for $inc, for example), just not accessible through the JS interface.

Comment by Kevin Pulo [ 15/Jun/14 ]

I'd be happy with just 64-bit long integer, since that's all that's necessary to work with hashed shard keys (the real motivation behind this request). Plugging in an arbitrary-precision library would certainly be sufficient, and might enable other interesting use cases. Do any of them have an AGPL compatible license?

Comment by Matt Kangas [ 14/Jun/14 ]

Are you looking for an arbitrary precision math library in the shell? A number of these exist for JavaScript. We probably should not roll our own in any event.

Generated at Thu Feb 08 03:34:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.