Thursday, March 2, 2017

nodejs mongoose

found a good tutorial about mongoose

https://scotch.io/tutorials/using-mongoosejs-in-node-js-and-mongodb-applications

In Mongoose, a sort can be done in any of the following ways:
Post.find({}).sort('test').exec(function(err, docs) { ... });
Post.find({}).sort({test: 1}).exec(function(err, docs) { ... });
Post.find({}, null, {sort: {date: 1}}, function(err, docs) { ... });
Post.find({}, null, {sort: [['date', -1]]}, function(err, docs) { ... });
http://stackoverflow.com/questions/4299991/how-to-sort-in-mongoose


No comments:

Post a Comment