NodeJS + Node-MongoDB-native: sort objects in alphabet order

I'm trying to sort objects in collection by "name" parameter in alphabetical order. Here's the code I'm using:

app.get('/companies', loadUser, function(req,res){
            collection.find({}, { sort:[['name',-1]]},function(err, companies) {
                var companies_list = new Array();
                companies.each(function(err, company){

I actually don't understand how exactly sort parameter works and what is -1. The official documentation didn't help me. Thanks!


Your code looks fine. I'd rather use

{ sort: [['name': 'desc']] }

because it's more explicit. Both methods work though.

When omitting the sort-direction:

{ sort: 'name'}

it sorts ascending.

Need Your Help

Column html css

php html css html5 css3

I need to split a text in two columns, but my need is to print. I need to have the first text be filled with text and then let the text skip to the second column. The paper size is A4.

UIImageView displays MUCH faster than either CG or CALayer. Anyone know why?

ios uiimageview core-animation core-graphics calayer

I've written an app to test image performance on iOS. I've tried 3 different views, all displaying the same large PNG. The first is a view that draws using CGContextDrawImage(). The second sets ...