KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I would like to return the documents in an order sorted by which holds the lowest foo.bar value (which are array objects). I can do db.collection.find().sort({foo.0.bar: 1}) , but this only matches the first element in the array - and as you can see in the exampe below would sort item 1 first (foo.0.bar = 5), wheras I am looking to return item 2 first (foo.2.bar = 4) as it has the object with the lowest value. { "name": "Item 1", "foo": [ { "bar": 5 }, { "bar": 6 }, { "bar": 7 } ] } { "name": "item 2", "foo": [ { "bar": 6 }, { "bar": 5 }, { "bar": 4 } ] }
Tags (comma-separated)
Save Edits
Cancel