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
An alternative to using map/reduce, is to store the min value from the array out as a separate field in the document which you could then order on. When you add to the array, you also update this field if the new value is lower than the currently recorded minimum.
e.g. your first document would become this (note "minbar added"):
{
"name": "Item 1",
"minbar" : 5,
"foo": [
{
"bar": 5,
}
{
"bar": 6,
}
{
"bar": 7,
}
]
}