The first argument is the singular name of the collection your model is for. Mongoose automatically looks for the plural, lowercased version of your model name. Thus, for the example above, the model Tank is for the tanks collection in the database.
Messages.find().then(data => console.log(data)).catch(e => console.log(e))
function Routes() {
app.use(bodyParser())
app.use(router.routes())
app.use(router.allowedMethods())
router.get('/a', async (ctx) => {
try {
const messages = await Messages.find()
ctx.body = messages
} catch (e) {
console.log(e)
}
})
}
export default Routes
const allItems = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7']; // Все доступные элементы например лежат в бд
const getAllPages = (limitItemsOnPage) => { // функция возвращает доступное число страниц
return Math.ceil(allItems.length / limitItemsOnPage)
}
const getItemsOnPage = (pageNumber, limitItemsOnPage) => { // функция возвращает элементы для определенной страниы
return allItems.slice(limitItemsOnPage * (pageNumber - 1), limitItemsOnPage * pageNumber);
}
console.log(getAllPages(4)) // 2 - получаем количество страниц
console.log(getItemsOnPage(1, 4)) // ["Item 1","Item 2","Item 3","Item 4"] - элементы для страницы один
console.log(getItemsOnPage(2, 4)) // ["Item 5","Item 6","Item 7"] - элементы для страницы 2