I'm trying to implement in my Node Express paging project in a menu list, and I found this documentation low enough;
According to the instructions I first installed lib with this command;
npm install mongoose-paginate
Then I set up my model menu including this line of code;
var mongoosePaginate = require('mongoose-paginate');
And this one too;
schema.plugin(mongoosePaginate);
As shown below;
'use strict'
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
var mongoosePaginate = require('mongoose-paginate');
const schema = new Schema({
id: {
type: String,
trim: true
},
name: {
type: String,
trim: true
},
description: {
type: String,
trim: true
},
restaurantId: {
type: String,
trim: true
},
price: {
type: Number,
trim: true
},
})
schema.plugin(mongoosePaginate);
module.exports = mongoose.model('Menu', schema);
Then I created the method that will paginate like this below;
function getMenusPage (req, res) {
Menus
.find({ }, { page: 3, limit: 5 }, function(err, menu) {
if(err){
res.status(500).send({
message: 'Error na solicitação'
});
}else{
if(!menu){
res.status(404).send({
message: 'Não existe nenhum menu nesse registro'
});
}else{
res.status(200).send({
menu
});
}
}
})
}
You are not generating a bug in the code or console, what would you like to know is how will I test on Postman to know if the implementation is correct?
I tried to do it that way
router.get('/menuspage', controller.getMenusPage);
With this URL;
http://localhost:3000/menuspage
But I had the error 404