0

I make a query to the database . I response array. In the answer I need to get pages, select pages ,total. To transfer data to the client for pagination

       return db.Reviews.findOne({_id: mongoose.Types.ObjectId(options.news_id)}, {comments:1})
                .then(res => {
                    return {
                        comments: res.comments.map(el => {
                            return {
                                _id: el._id,
                                name: el.name,
                                author: el.author,
                                message: el.message,
                                createdAt: el.createdAt
                            };
                        }),
                        count: {
                            total: res.comments,
                            pages: Math.ceil(res.comments / 
                            Number(param.limit)),
                            select_page: param.page,
                            limit: param.limit,
                            offset: param.offset,
                        }

0 Answers0