1

I am little familiar with sails and mongoDB, Here i want to know how to sort the data while selecting from collection in DESC order.

Here i enclosed my controller function:

listall : function(req, res){
        var userId = req.session.passport.user;
        User.find().sort( { '_id': -1 } ).where({
            id: userId
        }).exec(function(err, data) {
            Listing.find().where({
                userid : userId
            } ).exec(function(err, listdata){
                console.log(listdata);
                res.view('dashboard/listing', {
                'userdata': data,
                'userlisting' : listdata
            });
            });

        });

Here my sorting is not done, it fetch the rocord in ASC order. Please guide me where i am doing mistake.

Thanks & Regards

Rahul Saxena
  • 465
  • 4
  • 15

1 Answers1

1

Heads up

sails-mongo maps the logical id attribute to the required _id physical-layer mongo id. In the current version of sails-mongo, you should not sort by id.

See the sails-mongo Documentaion

Vishnu
  • 11,614
  • 6
  • 51
  • 90