0

I am new to keystone.js. I have a data in this format:

{ _id: 5551823e7771fc3f0decb03e,
       slug: 'marketing-manager',
       title: 'marketing manager',
       __v: 0,
       description: '<p>marketing stuff</p>',
       location: 'London',
       order: '2',
       orderno: 2 
},
{
       _id: 5552fb667ebab90c0e8b0440,
       slug: 'a-web-developer',
       title: 'a Web developer',
       __v: 0,
       description: '<p>Keystone web developer.</p>',
       location: 'India',
       order: '1',
       orderno: 1 
}

I want to order these data with orderno.

And I am using this query:

view.query('Jobs', keystone.list('Job').model.find().sort('orderno'));
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Sonia Bhatia
  • 146
  • 16

2 Answers2

1

Using suggestions from this and that, you could try the following:

var keystone = require('keystone'),
    Job = keystone.list('Job');

exports = module.exports = function(req, res) {

    var view = new keystone.View(req, res); 
    // LOAD Jobs
    // ------------------------------   
    view.on('init', function(next) {        
        Job.model.find()            
            .sort('orderno')
            .exec(function(err, jobs) {
                if (err) return res.err(err);
                res.jobs = topics;
                next();
            });

    }); 

    view.render('site/jobs');   
}
chridam
  • 100,957
  • 23
  • 236
  • 235
0

Here is the syntax for sortinng.

model.find().sort({name: 'criteria'}).exec(function(err, model) { ... }

And criteria can be any of the below:

asc, desc, ascending, descending, 1, or -1

Here, asc, ascending and 1 is Ascending Order And desc, descending and -1 is Descending Order.

Ajay Gupta
  • 2,867
  • 23
  • 28