[SERVER-50579] $mod truncates divisor and remainder to int value Created: 27/Aug/20  Updated: 28/Oct/20  Resolved: 09/Sep/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.0.19
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Nikita Lapkov (Inactive) Assignee: Nikita Lapkov (Inactive)
Resolution: Duplicate Votes: 0
Labels: neweng, qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-32960 $mod has inconsistent rounding/trunca... Closed
Sprint: Query 2020-09-21
Participants:

 Description   

$mod treats it's divisor and remainder arguments as int values. This could lead to unexpected behaviour when these arguments are larger than int. For example:

> db.createCollection('test')
> db.test.insert([{a: 4000000000}])
> db.test.find({a: {$mod: [4000000000, 0]}})

The last query should return the single record from the test collection, but returns nothing instead.



 Comments   
Comment by Nikita Lapkov (Inactive) [ 09/Sep/20 ]

We have decided to mergeĀ SERVER-32960 with this issue because they are editing the same code region and one commit would rewrite the other one.

Comment by Asya Kamsky [ 01/Sep/20 ]

Note that using $expr and aggregation expression this seems to work correctly:

db.test.find({$expr:{$eq: [0, {$mod: ["$a", 4000000000]}]}})
{ "_id" : ObjectId("5f4e6784e14d37572a3ab735"), "a" : 4000000000 }
db.test.find({a: {$mod: [4000000000, 0]}})
/* nothing */
db.test.find({a: {$mod: [400000000, 0]}})
{ "_id" : ObjectId("5f4e6784e14d37572a3ab735"), "a" : 4000000000 }

Generated at Thu Feb 08 05:23:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.