-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
Description
Summary
The BitwiseOperatorBuilder class in Update.java currently only provides long parameter versions for the and(), or(), and xor() methods. When passing an int value, Java's implicit type conversion promotes it to long, which results in the MongoDB document storing the value as a 64-bit integer (NumberLong) instead of a 32-bit integer (NumberInt).
Current Behavior
Update update = new Update().bitwise("field").or(16);
// Results in: { "$bit": { "field": { "or": NumberLong(16) } } }Even though 16 is an int, and field stored int value, it gets converted to long and stored as NumberLong in MongoDB. A simple example blow:
https://github.com/victorljii/spring-data-mongodb-lab
Proposed Solution
Add int overloads for all three bitwise methods:
public Update and(int value) {
addFieldOperation(BitwiseOperator.AND, value);
return reference;
}
public Update or(int value) {
addFieldOperation(BitwiseOperator.AND, value);
return reference;
}
public Update xor(int value) {
addFieldOperation(BitwiseOperator.AND, value);
return reference;
}The underlying addFieldOperation method already accepts Number, so this change is straightforward and backward-compatible.
Why This Matters
- Type Preservation: MongoDB distinguishes between 32-bit and 64-bit integers. Applications that rely on specific integer types for schema consistency or interoperability with other systems may be affected.
- Consistency: Other methods in
Update(e.g.,inc(String key, Number inc)) already acceptNumbertype, allowing type preservation. - API Completeness: Providing both
intandlongoverloads gives developers explicit control over the stored type.
JamiKX1cnlkl and JamiKX1
Metadata
Metadata
Assignees
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged