Wednesday, January 18, 2017

Select prices in ascending/Decending order where price exist

Select prices in ascending order where price exist

Asending:

db.products.find({price.{$exists.true}},(name:1,price:1}.sort({price:1})


Decending:

db.products.find({price.{$exists.true}},(name:1,price:1}.sort({price:-1})


Order by 2 fields:

db.customer.find().sort({lastname:1, first:1}) order by lastname, firstname


Order by 2 fields:

db.books.find().sort({author:1, date_posted:-1})

No comments:

Post a Comment