Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int64 support #2190

Closed
Romaxx opened this issue May 29, 2020 · 2 comments
Closed

int64 support #2190

Romaxx opened this issue May 29, 2020 · 2 comments

Comments

@Romaxx
Copy link

Romaxx commented May 29, 2020

Q A
Version 2.1.0

I want to use int64 fields in my db to do a 64 bitmask permission system (32bits it's quite short for some rare cases, but it append..), by default Field(type="integer") are int32 (checked with mongodb compass), and I need to change it manually to int64.
My server is under Php 64bits version so I can use MongoDB\BSON\Int64, is there an option field or a thing to specify int64 in schema ? Thank you

@malarzm
Copy link
Member

malarzm commented May 29, 2020

I believe the best would be adding a new type to handle int64 since it requires specjal care. You could take a page from #2128 where we've added decimal type. Also we will appreciate a PR adding the type to ODM!

@malarzm malarzm added this to the 2.x milestone May 29, 2020
@malarzm malarzm added this to 2.x in Roadmap May 29, 2020
@alcaeus alcaeus removed the Feature label May 29, 2020
@alcaeus alcaeus removed this from 2.x in Roadmap May 29, 2020
@alcaeus alcaeus removed this from the 2.x milestone May 29, 2020
@alcaeus
Copy link
Member

alcaeus commented May 29, 2020

On 64-bit platforms, the driver will store integer values as int32 bson type as long as its value fits into 32 bits. Once the value exceeds the maximum size for 32-bit integers, it is stored as int64 type: https://github.com/mongodb/mongo-php-driver/blob/master/src/bson-encode.c#L33..L37

On 32-bit platforms, the driver always stores integer values as 32-bits. The MongoDB\BSON\Int64 class is to allow the driver to correctly return int64 values (that may have been stored in the database on a different platform) by wrapping them in a value object and storing them as a string internally.

There is no special handling necessary to get the driver to store a 64-bit value, as long as you are running on a 64-bit platform.

@alcaeus alcaeus closed this as completed May 29, 2020
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

No branches or pull requests

3 participants