在数组对象中分页

时间:2019-06-01 14:57:01

标签: mongoose paginate

在我的情况下,我只想在对象中使用分页表达。

我现在有那个:

  async get(req, res) {
    try {

      const comment = await this.commentService.paginated(
       {
         piinsId: req.params.id,
       },
       {
        // I think I need to specify the field just here
       },
      req.query)


     return res.status(201).json({
      status: 201,
      result: comment
      });
    } catch(err) {
      throw err
    }
  }

我得到这个结果:

{
    "status": 201,
    "result": {
        "results": [
            {
                "_id": "5cf20903b23ae85aba77ae6f",
                "piinsId": "5cf20903b23ae85aba77ae70",
                "comment": [
                    {
                        "modified": false,
                        "_id": "5cf2090eb23ae85aba77ae71",
                        "text": "un commentaire\n",
                        "idProfil": "5cf18c4d7958c72df7faa595",
                        "createdDate": "2019-06-01T05:11:42.829Z"
                    },

                    {
                        "modified": false,
                        "_id": "5cf20d72cf519b5aed548974",
                        "text": "voilax\n",
                        "idProfil": "5cf18c4d7958c72df7faa595",
                        "createdDate": "2019-06-01T05:30:26.440Z"
                    }
                ],
                "__v": 0,
            }
        ],
        "itemCount": 1,
        "perPage": 25,
        "hasPrevPage": false,
        "hasNextPage": false,
        "currentPage": 1,
        "pageCount": 1,
        "undefined": 1,
        "prev": null,
        "next": null
    }
}

我想获得所有统计信息,而不是外部数据。 谢谢您的解决方案。因为我没有太多这样的例子

0 个答案:

没有答案