The method process of MongoDB database to solve the integer problem

The method process of MongoDB database to solve the integer problem

The integer problem mentioned in this article is actually not a problem of MongoDB, but a problem of PHP driver: MongoDB itself has two integer types, namely: 32-bit integer and 64-bit integer, but the old version of the PHP driver does not care whether the operating system is 32 The bit is still 64 bits, and all integers are treated as 32-bit integers, resulting in 64-bit integers being truncated. In order to solve this problem while maintaining compatibility as much as possible, the new version of the PHP driver has added the mongo.native-long option, in order to treat integers as 64-bit in 64-bit operating systems. If you are interested, please refer to: 64- bit integers in MongoDB. So does the PHP driver really solve the integer problem completely? NO! There are still bugs when dealing with group operations: To illustrate the problem, let’s first generate some test data: <?php ini_set(‘mongo.native_long’, 1); $instance = new Mongo(); $instance = $instance->selectCollection(‘test’, ‘test’); for ($i = 0; $i < 10; $i++) { $instance->insert(array( ‘group_id’ => rand(1, 5), ‘count’ => rand(1, 5), )); } ?> Let’s use the group operation to group by group_id and calculate the count: <?php ini_set(‘mongo.native_long’, 1); $instance = new Mongo();…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索