本文介绍了MongoDB \ Driver \ Exception \ InvalidArgumentException您的平台上检测到整数溢出:300000000000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用laravel为我的文档建立索引时出现错误.

I'm getting error when i try indexing my document using laravel.

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

This is my main code. By using die statements, I came to know that i'm getting this error "[MongoDB\Driver\Exception\InvalidArgumentException] Integer overflow detected on your platform: 300000000000" as soon as it executes first line :$users = 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的接口. 我的用户模型看起来像这样

I am using https://github.com/jenssegers/laravel-mongodb to interface Laravel and mongoDB. My User model looks like this

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

Test4包含大数据.但是,我确保我的映射中没有任何整数,这可能会导致整数溢出错误.请帮我.我是Laravel和MongoDB的新手我很乐意提供可能需要的其他任何信息.

Test4 contains big data. However, i've made sure i don't have any integer in my mapping that might cause integer overflow error. Kindly help me out. I am new to Laravel and MongoDBI would be happy to provide any further info that might be required.

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

Also when i try to decrease No. of fields in mapping and indexing, i get this error " PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 40 bytes) in C:\xampp\htdocs\ProTest1\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Query\Builder.php on line 392"

推荐答案

感谢尼尔·伦恩(Neil Lunn),您的反馈确实有所帮助.实际上,我一次要访问所有数据,而这会占用大量内存.所以,我改为尝试使用下面的代码一次提取数据块.

Thanks Neil Lunn, your feedback really helped. Actually i was accessing all the data at a time which was consuming large memory. So instead, i tried extracting chunk of data at a time, using below code, which worked.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:59