[DOCS-6999] Comment on: "manual/reference/operator/meta/orderby.txt" Created: 19/Jan/16  Updated: 03/Nov/17  Resolved: 13/Apr/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Eran Sadeh Assignee: Kay Kim (Inactive)
Resolution: Incomplete Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Win7

Location: https://docs.mongodb.org/v3.0/reference/operator/meta/orderby/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
Referrer: https://www.google.co.il/
Screen Resolution: 1680 x 1050
repo: docs
source: reference/operator/meta/orderby


Participants:
Days since reply: 7 years, 44 weeks, 1 day ago

 Description   

I tried to sort results by qty field, using the _addSpecial method. Didn't work.
See screenshot in this link:
https://drive.google.com/file/d/0B6Kp8wtpfCCpYXgxUFVib1BaR1U/view?usp=sharing

Thank you.



 Comments   
Comment by Kay Kim (Inactive) [ 13/Apr/16 ]

Resolving as I'm not sure which MongoDB version is being used.

Comment by Kay Kim (Inactive) [ 19/Jan/16 ]

Hi Eran -
which version of mongodb are you using? For 3.0, the addSpecial ("$orderby") should work:

> db.products.find( { }, { item: 1, qty: 1, _id: 0 } )._addSpecial( "$orderby", { qty: -1 } )
{ "item" : "card", "qty" : 500 }
{ "item" : "Galaxi 3", "qty" : 50 }
{ "item" : "iPhone 4", "qty" : 30 }
{ "item" : "iPhone 5s", "qty" : 20 }

However, starting in 3.2, use sort() method:

> db.products.find( { }, { item: 1, qty: 1, _id: 0 } ).sort( { qty: -1 } )
{ "item" : "card", "qty" : 500 }
{ "item" : "Galaxi 3", "qty" : 50 }
{ "item" : "iPhone 4", "qty" : 30 }
{ "item" : "iPhone 5s", "qty" : 20 }

Generated at Thu Feb 08 07:53:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.