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

标签 mongodb laravel elasticsearch jenssegers-mongodb

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

这是我的主要代码。通过使用 die 语句,我知道我在执行第一行时立即收到此错误“[MongoDB\Driver\Exception\InvalidArgumentException] 在您的平台上检测到整数溢出:300000000000”:
$users = 用户::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 fatal error :C:\xampp\htdocs\ProTest1\vendor\中允许的内存大小为 134217728 字节用尽(试图分配 40 字节) 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);
  }
});

关于MongoDB\Driver\Exception\InvalidArgumentException 在您的平台上检测到整数溢出 : 300000000000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44646193/

相关文章:

php - 为什么 GridFS 文件名和字节为空?

node.js - 我想在使用 node.js 完成所有 promise 后将数据插入 mongodb

php - Lumen Routes 显示 404,root route 除外

elasticsearch - 当Elasticsearch中有多个版本时,Update Builder会给出较晚的响应?

ruby-on-rails - 使用 Elasticsearch/Tire 通过时间表查找开放商店

elasticsearch - 使用嵌套查询时出现 Elasticsearch 问题

json - 以 JSON 格式打印出 MongoDB 文档

node.js - 更新模型实例

php - 没有订阅的 Laravel 收银台

php - Laravel 8 使用相同的形式进行编辑和创建,