MongoDB\Driver\Exception\InvalidArgumentException 在您的平台上检测到整数溢出:300000000000

MongoDB\Driver\Exception\InvalidArgumentException Integer overflow detected on your platform: 300000000000

当我尝试使用 laravel 索引我的文档时出现错误。

这是我的主要代码。通过使用 die 语句,我开始知道我在执行第一行时收到此错误“[MongoDB\Driver\Exception\InvalidArgumentException] 在您的平台上检测到整数溢出:300000000000”: $用户 = User::all();

$users = User::all();
foreach ($users as $user) {
        $temp=$user['attributes']; 
        unset($temp['_id']);
             $params = [
              'index' => 'test_index',
              'type' => $temp['vehicle_type'],
          'id' => $temp['lid'],
          'body' => $temp
        ];
        print_r($params); die;
     $response = $client->index($params);
     set_time_limit(100);
 }
    }``

我正在使用 https://github.com/jenssegers/laravel-mongodb 连接 Laravel 和 mongoDB。 我的用户模型如下所示

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent 
{
    protected $connection = 'mongodb';
    protected $collection = 'Test4';  
}

Test4 包含大数据。但是,我已经确定我的映射中没有任何可能导致整数溢出错误的整数。请帮帮我。我是 Laravel 和 MongoDB 的新手 我很乐意提供可能需要的任何进一步信息。

此外,当我尝试减少映射和索引中的字段数时,出现此错误“PHP 致命错误:C 中允许的 134217728 字节内存大小已耗尽(尝试分配 40 字节): \xampp\htdocs\ProTest1\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Query\Builder.php 第 392 行

感谢 Neil Lunn,您的反馈真的很有帮助。实际上我一次访问了所有数据,这消耗了大量内存。因此,我尝试使用以下有效的代码一次提取大量数据。

User::chunk(100, function ($users) {
    foreach ($users as $user) {
    $temp=$user['attributes']; 
    unset($temp['_id']);
         $params = [
          'index' => 'test_index',
          'type' => $temp['type'],
          'id' => $temp['lid'],
          'body' => $temp
        ];
     $client = Elasticsearch::create()->build();
     $response = $client->index($params);
  }
});