0
votes

The project uses Api Platform with mongodb. I have a Player document with an sort on lastName. With 5000 players it works. When I test with 200,000 players, I have an error:

Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.

I need to add "allowDiskUse: true" in the options of the request.

I tried adding it directly into the ApiPlatform code to test and it works! (but I can not add it to the library).

My question is: How to add the option "allowDiskUse: true" in the mongodb query with Api Platform?

/**
 * @ODM\Document(repositoryClass="App\Repository\PlayerRepository")
 * @ApiResource(
 *     attributes={"orders"={"lastName"= "ASC"}},
 *     collectionOperations={"get", "post"},
 *     itemOperations={"get", "put"},
 *
 *     normalizationContext={"groups"={"player"}},
 *     denormalizationContext={"groups"={"player"}}
 *     )
 */
class Player
{
    /**
     * @ODM\Id
     * @Groups({"player"})
     */
    private $id;

    /**
     * @ODM\Field(type="string")
     * @Groups({"player"})
     */
    private $optaId;

    /**
     * @ODM\Field(type="string")
     * @Groups({"player"})
     */
    private $firstName;

    /**
     * @ODM\Field(type="string")
     * @Groups({"player"})
     */
    private $lastName;
1

1 Answers

1
votes

You can do it by adding

* @ApiResource(attributes={
*     "doctrine_mongodb"={
*       "execute_options"={
*         "allowDiskUse"=true
*       }
*     }
* })