2

I use laravel-mongodb by jenssegers. I want to query a huge amount of data with order by and this is my query :

$stores = \App\StoreTransaction::where('date_time','>',1489944515)
        ->orderBy('date_time', 'asc')->get();

But I got this error:

Sort exceeded memory limit of 104857600 bytes

I know I should add allowDiskUse true to my query but how can i add it to mongodb jenssegers package ?

3
  • it would be more feasible to create an index on date_time Commented Feb 3, 2018 at 12:25
  • I'm not sure that you want to get all the results into memory. You should be able to use a cursor to get N results paginated. Commented Feb 3, 2018 at 12:25
  • Try $stores = \App\StoreTransaction::where('date_time','>',1489944515) ->orderBy('date_time', 'asc')->paginate(100) to get 100 records per time into memory. I'm not sure but I hope that this is implemented lazily. Otherwise, you want to do this using the cursor from a raw database command Commented Feb 3, 2018 at 12:29

2 Answers 2

6

Please do not modify vendor files

In your case, use the "options" method to allow disk use:

$stores = \App\StoreTransaction::where('date_time','>',1489944515)        
->orderBy('date_time', 'asc')
->options(['allowDiskUse' => true])
->get();
Sign up to request clarification or add additional context in comments.

1 Comment

Hoa can we done this when using aggregate query?
-1

Goto "vendor/mongodb/mognodb/src/Operation/Aggregate.php" Goto "line 133"

replace 'allowDiskUse' => false, per 'allowDiskUse' => true.

1 Comment

Editting vendor code is not a good suggestion. As it's easy to lose sight where the changes were made and can cause weird and hard to find bugs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.