Anybod familiar with mongoose paginate? how to paginate and filter?

First of all… can you also filter with mongoose?

Anyway… my code has broke down after trying to modify the route by adding pagination from mongoose…

I went from this

const router = require("express").Router();
let part = require("../Models/parts-schema");

router.route("/").get((req, res) => {
    .then((part) => res.json(part))
    .catch((err) => res.status(400).json("error: + err"));
module.exports = router;

to this…

const router = require("express").Router();
let part = require("../Models/parts-schema");

router.route("/").get(async (req, res) => {
  const limit = parseInt(req.query.limit, 100) || 100;
  const page = parseInt(, 1) || 1;
  const parts = await part.paginate({}, { limit, page });

module.exports = router;

And now I can’t read anything on the front end…

  1. I am trying to add the .catch error, but somehow I am getting syntax errors and it breaks my backend connection and can’t test anything with Insomnia.

  2. My front end when I get to the page went blank and get console errors.

  3. Can I somehow add a global filter in the route as well?

The front errors I am getting are below, but it was working fine with my previous router code…

The frontend code is below… I haven’t changed anything, but I would suppose I need to add more things to work with pagination and filtering…

import React, { Component } from "react";
import { Link } from "react-router-dom";
import axios from "axios";

const PartList = (props) => (

export default class TableList extends Component {
  constructor(props) {

    this.state = { part: [] };

  componentDidMount() {
      .then((response) => {
        this.setState({ part: });
      .catch((error) => {

  partMapping() {
    return => {
      return <PartList part={currentPart} key={currentPart._id} />;

  render() {
    return (
        <h1>I am the table list component</h1>;

Yes, I added key={currentPart._id} to the mapping… still get a broken code with the new router code and can’t see anything on the frontend.

And yes… I also added mongoose paginate…

const mongoose = require("mongoose");
const mongoosePaginate = require("mongoose-paginate-v2");
const Schema = mongoose.Schema;

const partSchema = new Schema({
  Reference: { type: String },
  Description: { type: String },
  Replacements: { type: String },


const part = mongoose.model("part", partSchema);

module.exports = part;

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.