samedi 30 mai 2020

Mongoose-random Doenst Show Properly

I am using mongoose-random: 'https://github.com/matomesc/mongoose-random' I want to show my articles in a random sequence. But findRandom() is not working.

My app.js

app.get('/', function (req, res) {
  var perPage = 5
  var page = req.query.query;
  Metin
  .findRandom()
  .skip((perPage * page) - perPage)
  .limit(perPage)
  .exec(function(err, metins) {
      Metin.count().exec(function(err, count) {
          if (err) return next(err)
          res.render('index', {
              current: page,
              pages: Math.ceil(count / perPage),
              metins: metins,
          })
      })
  })
});

Also in my model.js, I have implemented:

 var random = require('mongoose-random');
    .
    .
    .
    metinSchema.plugin(random);

I couldnt understand why it is not working. The problem is: It doesnt gives any error but at the same time it doesnt show my articles(metin).Just shows the page without my articles. When just use find({}) my articles are shown. I couldnt understand why it is not working?

Can you please help to me?




Aucun commentaire:

Enregistrer un commentaire