如何在Api平台的Mongodb请求中添加选项“ AllowDiskUse:true”?

时间:2019-07-24 12:42:37

标签: mongodb symfony doctrine-odm api-platform.com

该项目将Api平台与mongodb结合使用。 我有一个播放器文档,其中的姓氏排序。它可以容纳5000名玩家。 当我与200,000名玩家进行测试时,我出现了一个错误:

  

排序超出内存限制104857600字节,但未选择加入   外部排序。中止操作。传递allowDiskUse:true以选择   内。

我需要在请求的选项中添加“ allowDiskUse:true”。

我尝试将其直接添加到ApiPlatform代码中进行测试,并且可以正常工作! (但是我无法将其添加到库中。)

我的问题是:如何在Api Platform的mongodb查询中添加选项“ allowDiskUse:true”?

/**
 * @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 个答案:

答案 0 :(得分:1)

您可以添加

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